Python create xml from xsd Python create xml from xsd xml xml

Python create xml from xsd


I think, generateDS is the solution to your 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 peoplerootObject = people.parse('people.xml')

within 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.


There are some projects on github that do that by using xmlschema library, for instance fortesp/xsd2xml or miaozn/xsd2xml (python2)

For instance with the former:

xmlgenerator = XMLGenerator('resources/pain.001.001.09.xsd', True, DataFacet())print(xmlgenerator.execute()) # Output to consolexmlgenerator.write('filename.xml') # Output to file

Unfortunately none of these are properly packaged though.