I am having a hard time getting started with PyXB.
Say I have an XSD file (an XML schema). I would like to:
- Use PyXB to define Python objects according to the schema.
- Save those objects to disk as XML files that satisfy the schema.
How can I do this with PyXB? Below is a simple example of an XSD file (from Wikipedia) that encodes an address, but I am having a hard time even getting started.
<?xml version="1.0" encoding="utf-8"?>
<xs:schema elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="Address">
<xs:complexType>
<xs:sequence>
<xs:element name="FullName" type="xs:string" />
<xs:element name="House" type="xs:string" />
<xs:element name="Street" type="xs:string" />
<xs:element name="Town" type="xs:string" />
<xs:element name="County" type="xs:string" minOccurs="0" />
<xs:element name="PostCode" type="xs:string" />
<xs:element name="Country" minOccurs="0">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:enumeration value="IN" />
<xs:enumeration value="DE" />
<xs:enumeration value="ES" />
<xs:enumeration value="UK" />
<xs:enumeration value="US" />
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
Update
Once I run
pyxbgen -u example.xsd -m example
I get a example.py
that has the following classes:
example.Address example.STD_ANON
example.CTD_ANON example.StringIO
example.CreateFromDOM example.pyxb
example.CreateFromDocument example.sys
example.Namespace
I think I understand what CreateFromDocument
does - it presumably reads an XML and creates the corresponding python object-, but which class do I use to create a new object and then save it to an XML?