[XML-SIG] New XML module

Uche Ogbuji Uche.Ogbuji at fourthought.com
Fri Nov 11 21:05:49 CET 2005

On Thu, 2005-11-10 at 19:53 -0800, Guido van Rossum wrote:
> 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:
> https://sourceforge.net/tracker/?func=detail&atid=305470&aid=1337648&group_id=5470
> 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>
>     </outer>'''
>     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>')
> <outer
>     id="1"
>     name="foo">
>   <inner special="false">blah, blah</inner>
> </outer>

Feels a bit like XIST.  Is the class def per element type mandatory?  If
not, what do defaults look like?

For my part, I think that there are so many XML processing idioms based
on user preference that I'd balk at blessing any one.  In retrospect I
think it was a mistake to even bless SAX and DOM by putting them in the
stdlib.  I think that XML processing is parallel to Web frameworks in
this respect.  I suppose an equivalent of BaseHTTPServer makes sense,
but IMO minidom, SAX and pulldom already serve for that.

Nevertheless, I've been looking forward to seeing this module of yours
for a while and I'll try to test it out and provide some feedback.

Uche Ogbuji                               Fourthought, Inc.
http://uche.ogbuji.net                    http://fourthought.com
http://copia.ogbuji.net                   http://4Suite.org
Articles: http://uche.ogbuji.net/tech/publications/

More information about the XML-SIG mailing list