XML 模式到 C++ 类

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/445905/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 15:23:35  来源:igfitidea点击:

XML Schema to C++ Classes

c++xmlqtxsdcode-generation

提问by Andre

I have to write a C++ Application (using the Qt Framework for the GUI) that can edit data stored in xml files described by a xsd schema file. Is there a tool to convert the xsd schema into C++ Classes?

我必须编写一个 C++ 应用程序(使用 Qt 框架作为 GUI),它可以编辑存储在由 xsd 架构文件描述的 xml 文件中的数据。是否有将 xsd 模式转换为 C++ 类的工具?

采纳答案by mickus

Sounds to me like CodeSynthesisis exactly what you are looking for. It's open source and c++.

在我看来,CodeSynthesis正是您要寻找的。它是开源和 C++。

回答by DavidRR

See XmlPlus-xsd2cppat Google:

请参阅Google 上的XmlPlus-xsd2cpp

XmlPlus xsd2cpp provides "simple to use" C++ XML data-binding through W3C XML-Schema.

XmlPlus xsd2cpp 通过 W3C XML-Schema 提供“易于使用”的 C++ XML 数据绑定。

Usage of XmlPlus is covered by the GNU Lesser General Public License

GNU 宽松通用公共许可证涵盖了 XmlPlus 的使用

回答by bhelm

gSOAP Toolkitcan do this too! Its is lightweight, and supports C/C++. I have already used it in very demanding projects with success. Also, its licensed under GPL2.

gSOAP Toolkit也可以做到这一点!它是轻量级的,并且支持 C/C++。我已经成功地在要求很高的项目中使用了它。此外,它在 GPL2 下获得许可。

Portability: gSOAP supports most platforms, including embedded systems and small OS (for example WinCE, Symbian, and PalmOS). Portability is tested for Windows (98, XP, Vista), Linux, Unix, Mac OS X, Solaris, HP-UX, AIX, FreeBSD, TRU64, Irix, QNX, and VxWorks.

可移植性:gSOAP 支持大多数平台,包括嵌入式系统和小型操作系统(例如 WinCE、Symbian 和 PalmOS)。可移植性已针对 Windows(98、XP、Vista)、Linux、Unix、Mac OS X、Solaris、HP-UX、AIX、FreeBSD、TRU64、Irix、QNX 和 VxWorks 进行了测试。

回答by Raphael Bossek

Objective Systems, Inc. XBinder XML Schema Compiler(not only für C++).

Objective Systems, Inc. XBinder XML Schema Compiler(不仅适用于 C++)。

回答by Tom

Altova XML Spycan generate C++ from an XSD, it's commercial but there's a 30 day free trial if you want to try it out.

Altova XML Spy可以从 XSD 生成 C++,它是商业的,但如果您想尝试一下,可以免费试用 30 天。

回答by Pete Cordell

Codalogic LMXis also an option.

Codalogic LMX也是一种选择。

回答by ChrisW

There's a Microsoft tool which does this, I think, called xsd.exe(but I haven't tried it myself).

我认为有一个 Microsoft 工具可以执行此操作,称为xsd.exe(但我自己还没有尝试过)。

回答by user6269400

All the generators are absolutely terrible.

所有的发电机都非常糟糕。

XSD describes a class hierarchy in which classes contain subclasses, which may contain other subclasses and all you want to do is represent it in the same way.

XSD 描述了一个类层次结构,其中类包含子类,子类可能包含其他子类,您要做的就是以相同的方式表示它。

For example if this is your schema:

例如,如果这是您的架构:

<xs:element name="shipto">
  <xs:complexType>
    <xs:sequence>
      <xs:element name="name" type="xs:string"/>
      <xs:element name="address" type="xs:string"/>
      <xs:element name="city" type="xs:string"/>
      <xs:element name="country" type="xs:string"/>
    </xs:sequence>
  </xs:complexType>
</xs:element> 

You'd want to produce something like:

你想要产生类似的东西:

class shipTo
{
  private:
    string name;
    string address;
    string city;
    string country;

  public:
    set_Name();
    get_Name();
    ...
}

You're not going to find it. The closest thing I have found is xjc, which is for Java.

你不会找到它的。我发现的最接近的是 xjc,它用于 Java。

You'd expect something as BASIC as this functionality would exist, but I haven't found it yet, and yes, I have used Altova XML-Spy. I'm seriously surprised anybody would suggest this as a code generator. Its generated code is absolutely awful.

您可能会期待 BASIC 之类的东西,因为此功能会存在,但我还没有找到,是的,我已经使用了 Altova XML-Spy。我很惊讶有人会建议将此作为代码生成器。它生成的代码非常糟糕。

I'm writing a lex/bison parser to do this for my project because all the tools I've been able to find so far produce fairly horrible code. Altova has a 30 day trial period, if you don't believe me, try it. It is easier to write a lex/bison parser for my XSD than it is to use a $500 professional code package that produces a terrible class representation.

我正在编写一个 lex/bison 解析器来为我的项目执行此操作,因为到目前为止我能够找到的所有工具都会产生相当糟糕的代码。Altova 有 30 天的试用期,如果您不相信我,请尝试一下。为我的 XSD 编写一个 lex/bison 解析器比使用一个 500 美元的专业代码包更容易产生一个糟糕的类表示。

I can't believe people make use of XML in C++ because the tools for it are terrible.

我不敢相信人们在 C++ 中使用 XML,因为它的工具很糟糕。