Christos
Christos

Reputation: 31

read XSD and create corresponding XML

I have spent hours looking for this but I couldn't find any answer... I have an XSD file (given by another source) and I am trying to create an XML file that complies with that. I have all the data ready to data structures. All I need to do is to export data as XML BY FOLLOWING the XSD. Is that possible?

I am not looking to export XSD to XML, neither to validate XML nor to parse XML. I start from scratch, I read XSD and based on that I am trying to create XML by mapping my data structures to the allowed elements from XSD.

Conceptually, it seems doable.... however, I haven't found any answer yet. Any ideas and suggestions (preferably in Python 2) are more than welcome.

Upvotes: 2

Views: 7353

Answers (1)

Christos
Christos

Reputation: 31

I sorted it out and I reply to myself for other's benefit.

As nicely proposed, generateDS is the solution to the problem. Starting from chapter 5, the command

python generateDS.py -o people.py -s peoplesubs.py people.xsd

reads the XSD file and creates several classes and subclasses. It generates many data structures and getters and setters for accessing and using data :) If there is any XML file that complies with that XSD, it can be read straight away by using

import people
rootObject = people.parse('people.xml')

whithin the code. More information is given in chapter 12. The aforementioned classes also provide methods to export data as an XML format. The level of documentation is good and it is highly suggested to use this for any future project.

Have fun, C.

Upvotes: 1

Related Questions