Kortex786
Kortex786

Reputation: 1119

How to convert XSD to Python Class

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?

Upvotes: 53

Views: 74293

Answers (5)

Matt C
Matt C

Reputation: 1563

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 my 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!

Upvotes: 10

Marduk
Marduk

Reputation: 1132

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

Upvotes: 14

Kortex786
Kortex786

Reputation: 1119

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 !

Upvotes: 47

user9876
user9876

Reputation: 11102

PyXB: http://pyxb.sourceforge.net/

Upvotes: 9

S.Lott
S.Lott

Reputation: 391846

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

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

Upvotes: 2

Related Questions