[XML-SIG] New XML module

Guido van Rossum guido at python.org
Fri Nov 11 04:53:41 CET 2005

At Elemental I've had a lot of success with a simple module that
converts between Python data structures and XML. I mentioned this code
in a talk at EuroPython this summer and there was quite a bit of
interest in it (despite my emphasis on its limitations).

Encouraged by that interest I'm contributing the code to the PSF for
possible inclusion in the Python standard library. The first step of
contribution is to put it up on the SF tracker:


Since I'm not all that plugged into the Python XML community I'd like
to get some feedback on the code (I've subscribed to this list
specifically for that purpose).

A quick plug is the little test method included at the end of the code:

def _test():
    class Inner(ElementClass):
        __element__ = "inner"
        __attributes__ = {"special": Boolean}
        __characters__ = "text"
    class Outer(ElementClass):
        __element__ = "outer"
        __attributes__ = {"id": Integer, "name": String}
        __children__ = {Inner: "inner[]"}
    sample = '''<outer id="1" name="foo">
        <inner special="false">blah, blah</inner>
    outie = Outer.__parseText__(sample)
    print (outie.id, outie.name)
    for innie in outie.inner:
        print (innie.special, innie.text, str(innie))
    print outie

The output from running this is:

(1, 'foo')
(False, 'blah, blah', '<inner special="false">blah, blah</inner>')
  <inner special="false">blah, blah</inner>

--Guido van Rossum (home page: http://www.python.org/~guido/)

More information about the XML-SIG mailing list