ANN: generateDS.py 8a available
dkuhlman at rexx.com
Wed Dec 22 20:21:22 CET 2004
generateDS.py 1.8a has been released.
If you try it and have suggestions, comments, or bug reports,
please send them my way.
Where to find generateDS.py
You can find generateDS.py here:
What is new
Recent enhancements include the following:
- Mixed content -- generateDS.py now will generate code that
handles mixed content when the element definition includes the
attribute mixed="true". The generated code is awkward, but at
least you are not blocked completely when an XML Schema uses
- Element extensions -- generateDS.py now generates subclasses for
extensions, that is when an element definition contains
something like this:
There is an important limitation, however: member names
duplicated (overridden ?) in an extension generate erroneous
code. Sigh. I guess I needed something to do in 2005.
- Attribute groups -- generateDS.py now handles definition and use
of attribute groups, that is the use of something like the
<xs:attribute name="fruit" />
<xs:attribute name="vegetable" />
- Substitution groups -- generateDS.py now handles a *limited*
range of substitution groups, in particular it handles
substitution groups that involve complex types, but does not
handle those that involve (substitute for) simple types (for
example, xs:string, xs:integer, etc). This is because the code
generated for members defined as simple types does not provide
the needed information to handle substitution groups.
What is generateDS.py?
``generateDS.py`` generates Python data structures (for example,
class definitions) from an XML Schema document. These data
structures represent the elements in an XML document described by
the XML Schema. It also generates parsers that load an XML
document into those data structures. In addition, a separate file
containing subclasses (stubs) is optionally generated. The user
can add methods to the subclasses in order to process the contents
of an XML document.
The generated Python code contains:
- A class definition for each element defined in the XML Schema
- A main and driver function that can be used to test the
- A parser that will read an XML document which satisfies the XML
Schema from which the parser was generated. The parser creates
and populates a tree structure of instances of the generated
- Methods in each class to export the instance back out to XML
(method ``export``) and to export the instance to a literal
representing the Python data structure (method
The generated classes contain the following:
- A constructor method (__init__), with member variable
- Methods with names 'getX' and 'setX' for each member variable
'X' or, if the member variable is defined with
maxOccurs="unbounded", methods with names 'getX', 'setX',
'addX', and 'insertX'.
- A "build" method that can be used to populate an instance of the
class from a node in a minidom tree.
- An "export" method that will write the instance (and any nested
sub-instances) to a file object as XML text.
- An "exportLiteral" method that will write the instance (and any
nested sub-instances) to a file object as Python literals (text).
More information about the Python-list