ANN: generateDS.py 8a available

From: Dave Kuhlman (dkuhlman_at_rexx.com)
Date: 12/22/04


Date: Wed, 22 Dec 2004 19:21:22 GMT

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:

    http://www.rexx.com/~dkuhlman/generateDS.html
    http://www.rexx.com/~dkuhlman/generateDS-1.8a.tar.gz

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
  this feature.

- Element extensions -- generateDS.py now generates subclasses for
  extensions, that is when an element definition contains
  something like this:

      <xs:extension base="sometag">

  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
  following:

      <xs:attributeGroup name="favorites">
        <xs:attribute name="fruit" />
        <xs:attribute name="vegetable" />
      </xs:attributeGroup>
  

- 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
  document.

- A main and driver function that can be used to test the
  generated code.

- 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
  Python classes.

- 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
  ``exportLiteral``).

The generated classes contain the following:

- A constructor method (__init__), with member variable
  initializers.

- 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).

Dave

-- 
Dave Kuhlman
http://www.rexx.com/~dkuhlman


Relevant Pages

  • RE: XML documentation file name
    ... MSDN document on VB.NET Project Designer says "The Generate XML document ... XML documentation is automatically emitted into an XML ... Microsoft Online Community Support ...
    (microsoft.public.dotnet.languages.vb)
  • Re: XMLTextReader reading too many characters
    ... It was a very simple process to delete the extra tag. ... You do know about XML ... status isn't indicative of being capable of editing an XML document. ... If you claim there is a problem with XmlTextReader and an allegedly ...
    (microsoft.public.dotnet.xml)
  • Re: Storing hierarchies from XML into relational tables
    ... You haven't made clear what sort of relational tables you plan to use to store the data from your hierarchy. ... Parent VARCHAR ... Given an xml document that represents a heirarchy: ...
    (microsoft.public.sqlserver.xml)
  • XPathNavigator SetValue wipes out XmlType
    ... I have an xml document that I want to go through and set the values on ... I can iterate the document and get my XmlType and XmlBaseType values just ... Xml and Program.cs to recreate the problem. ...
    (microsoft.public.dotnet.languages.csharp)
  • insert method in ElementTree
    ... Python script reads XML document above into ElementTree. ... If there is a parent element that does not have the ... element with atribute createAnotherWhenCondition and that condition is ...
    (comp.lang.python)