10

I get several Datasets listed in a single xml File. I have to extract each dataset and do some operations depending on their values (not changing the content of the xml file). So I have to parse that file.

With the .Net Framework I would simply use the XSD tool to generate a matching class avoiding to write a parser myself. Unfortunately that project has to be done using Qt and mingw and I'm not sure if there is similar tool.

Is it possible to (auto)generate a c++/qt class from xsd?

If it is: how?

mbx
  • 6,292
  • 6
  • 58
  • 91
  • 1
    Hmmm... just fount this as well http://stackoverflow.com/questions/445905/xml-schema-to-c-classes – snoofkin May 22 '11 at 10:50

4 Answers4

7

Nice question! You should not worry if Qt has such a feature. You can use CodeSynthesisXSD which is open source. The you can combine the generated classes to your Qt project.

Narek
  • 38,779
  • 79
  • 233
  • 389
  • CodeSynthesis XSD seems to be what I am looking for – mbx May 22 '11 at 12:18
  • 1
    While the answer does offer an alternative I find it to be not a proper answer. First of all one should look into CodeSynthesisXSD's licensing policy, which is different from what Qt has. This can potentially lead (depending on the Qt project that the OP is working on) to legal issues. Second of all this is an external dependency, which (again depending on the Qt project) may be something that is to be avoided (for some reason). – rbaleksandar Mar 09 '18 at 10:48
1

You may want to check CodeSynthesis XSD see this

snoofkin
  • 8,725
  • 14
  • 49
  • 86
0

You can also use xsd.exe to generate C++ code. It goes with Visual Studio and xsd /language will show which languages do xsd.exe support which includes CPP also.

Nguyễn Đức Tâm
  • 1,017
  • 2
  • 10
  • 24
  • xsd.exe does not generate vanilla C++ (like C++03, C++11) but [C++/CLI](https://en.wikipedia.org/wiki/C%2B%2B/CLI) - you can see this by looking in the generated header: `#using – mbx Dec 02 '19 at 09:29
  • Yes, you're right. I'm facing the same problem now. So, after all, you use ``CodeSynthesisXSD`` does it generate vanilla C++ code? – Nguyễn Đức Tâm Dec 02 '19 at 09:51
  • I don't remember if I actually used it to generate the production code but I remember using it. – mbx Dec 02 '19 at 10:11
  • Using CodeSynthesis also provides the same output which is C++/CLI, not vanilla C++. ``#using #using #using #using `` include in the header file. – Nguyễn Đức Tâm Dec 02 '19 at 11:09
0

I think with xmlpatterns module in qt it should be really easy and qt way to parse the xsd and make the corresponding qt c++ representation.

mbx
  • 6,292
  • 6
  • 58
  • 91