XML Schema to C++ Classes [closed]

半城伤御伤魂 提交于 2020-01-09 06:19:13

问题


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?


回答1:


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




回答2:


See XmlPlus-xsd2cpp at Google:

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

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




回答3:


gSOAP Toolkit can 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.

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.




回答4:


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




回答5:


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




回答6:


Codalogic LMX is also an option.




回答7:


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




回答8:


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.

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.

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.

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.

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



来源:https://stackoverflow.com/questions/445905/xml-schema-to-c-classes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!