How to convert XSD to Python Class

Viewed 59714

I just want to know if there is a program that can convert an XSD file to a Python class as JAXB does for Java?

5 Answers

generateDS : I think this is the good tool I need

Edit : Actually, generateDS does very well the job !! It generates the Python class with all methods (setters and getters, export to XML, import from XML). It works very well !

For anyone coming across this question now (in 2021) I suggest checking out xmlschema

I tried the above suggestions (despite the EOL warnings), but wasn't enjoying the experience. Then I discovered xmlschema, and parsed by data in just 3 lines, including the import.

>> import xmlschema
>> data_schema = xmlschema.XMLSchema('my_schema.xsd')
>> data=data_schema.to_dict('my_data.xml')

The imported data is a nested dictionary, with keys and values that match the schema. Beautiful!

Related