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