generateDS.py generates Python classes that represent the elements
in an XML document, given an Xschema definition of the XML
The new extension will export a Python literal representation of
the XML document.
What It Does
When generateDS.py generates the Python source code for your
classes, this new feature also generates an "exportLiteral" method
in each class. If you call this method on the root (top-most)
object, it will write out a literal representation of your class
instances as Python code.
generateDS.py also generates a function at top level
(parseLiteral) that parses an XML document and calls the
"exportLiteral" method on the root object to write the data
structure (instances of your generated classes) as a Python module
that you can import to (re-)create instances of the classes that
represent your XML document.
Why You Might Care
This feature means that the classes that you generate from an XML
schema support the interchangeability of XML and Python literals.
This means that, given classes generated by generateDS.py for your
XML document type, you can perform the following transformations:
- Translate an XML document into a Python module containing a
literal definition of the contents of the XML document.
- Translate the literal definition of a Python data structure into
an XML instance document.
This capability enables you to:
- Work with an XML (text) document, then exchange it for a Python
text representation of the content of that document.
- Work with a Python literal text representation of your XML
document, then exchange that for an XML document that represents
the same content.
- "Freeze" your XML document as a Python module that you can
import. The module can be edited with your text editor, so
perhaps it would be better to say that it is frozen, but not too
hard. The classes that you generate with generateDS.py can be
1. Read in an XML document.
2. (Optionally) modify the Python instances that represent that
3. Write the instances out as a Python module that you can later
Where to Find It
You can find generateDS.py at:
dkuhlman at rexx.com