How to convert XSD to Python Class

Question:

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?

Asked By: Kortex786

||

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 !

Answered By: Kortex786

Look at http://pypi.python.org/pypi/rsl.xsd/0.2.3

Also, you might want http://pyxsd.org/ it works very nicely.

Answered By: S.Lott

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!

Answered By: Matt C

xsdata generates dataclasses from an XSD file. According to the documentation it was inspired by JAXB.

Answered By: Marduk