Module for converting XML to Python object(s)?

Peter Dobcsanyi peter at designtheory.org
Mon Aug 9 12:54:49 EDT 2004


Robert Oschler <no_replies at fake_email_address.invalid> wrote:
> Has anybody seen a Python module that will take an XML document (not a
> colossal one), and convert it to a Python nested class object?  I'm

I have something similar implemented in the "ext-rep" module of the
"pydesign" package.  Here is an excerpt from the documentation:

    XTree is a class to create and manipulate a labeled rooted tree data
    structure whose underlying raw data structure is a tree whose nodes are
    tuples of the structure:

	(node_name, {dictionary of attributes}, [list of children])

    The dictionary of attributes represents the label associated with the
    node. This raw tree is not accessed directly, however, but through the
    XTree object's interface. XTree, in fact, is a lazy recursive wrapper
    around the raw structure and hides the implementation details. From the
    user's point of view, the internal nodes of the tree presented this way
    are of the XTree type. The leaves of the tree are either childless XTree
    objects or some particular Python data types. Currently, the following
    Python data types can be used for leaves: integer, floating point,
    string, list of integers.

The module is specialized to a particular highly structured XML
document, but it should not be difficult to modify it for your needs.
The user can read the whole XML document in one step or alternatively as
a "stream" of sub XTree-s.

In fact, I have found this streaming Reader (parser + converter)
solution so useful that I am planning to make the module into a general
parameterizable module.

You can find documentation and the package at:

    http://designtheory.org/software/pydesign/

--             ,
    Peter Dobcsanyi



More information about the Python-list mailing list