End-to-end example with PyXB. From an XSD schema to an XML document End-to-end example with PyXB. From an XSD schema to an XML document python python

End-to-end example with PyXB. From an XSD schema to an XML document


A simple google search brings this: http://pyxb.sourceforge.net/userref_pyxbgen.html#pyxbgen

In particular the part that says:

Translate this into Python with the following command:

pyxbgen -u po1.xsd -m po1

The -u parameter identifies a schema document describing contents of a namespace. The parameter may be a path to a file on the local system, or a URL to a network-accessible location like http://www.weather.gov/forecasts/xml/DWMLgen/schema/DWML.xsd. The -m parameter specifies the name to be used by the Python module holding the bindings generated for the namespace in the preceding schema. After running this, the Python bindings will be in a file named po1.py.

EDIT Following your update:

Now that you have your generated Address class and all the associated helpers, look at http://pyxb.sourceforge.net/userref_usebind.html in order to learn how to use them. For your specific question, you want to study the "Creating Instances in Python Code" paragraph. Basically to generate XML from your application data you simply do:

import exampleaddress = Address()address.FullName = "Jo La Banane"# fill other members of address# ...with open('myoutput.xml', 'w') as file    f.write(address.toxml("utf-8"))

Now it's up to you to be curious and read the code being generated, pyxb's doc, call the various generated methods and experiment!