ANN: XMLBuilder 1.3

Mike Hostetler thehaas at
Tue Oct 5 17:49:18 CEST 2004

XMLBuilder is an easy way to generate XML.

New in Version 1.3:
    * Support for non-ascii character.
    * You can specify the encoding when making the object. If not
      specified, it defaults to UTF-8.
    * Specify if you want the resulting XML to be pretty-printed out.

Thanks to Luis Miguel Morillas for helping me with the encoding stuff,
and the patches.

The current version is always avaiable at:

It's easier to show you how XMLBuilder works than to tell you.  Here
is some samples:

>>>{"person": {"attr": {"type":"friend"},"last":"flintstone",
...          "first":"fred"}}
>>> print b1
<?xml version="1.0" encoding="utf-8"?>
  <person type="friend">

>>> b2 = XMLBuilder()
>>> b2.person={"attr":{"type":"boss"}, "last":"Slate", "first":"Mr."}
>>> print b2
<?xml version="1.0" encoding="utf-8"?>
<person type="boss"><last>Slate</last><first>Mr.</first></person>

>>> print(b1+b2)
<?xml version="1.0" encoding="utf-8"?>
<name><person type="friend"><last>flintstone</last><first>fred</first>
</person><person type="boss"><last>Slate</last><first>Mr.</first></person></name>

>>> nonascii ={u"français" : u"Comment ça va? Trés bien?",
...                u"deutsch" : u"viel Spaß"}
## encoding='local' means to use the local encoding, in my case ISO8859-1
>>> iso = XMLBuilder(encoding="local", pretty=True)
>>> iso.lang = nonascii
>>> print iso
<?xml version="1.0" encoding="ISO8859-1"?>
    Comment ça va? Trés bien?
    viel Spaß

A more concrete example is at:
Mike Hostetler  

More information about the Python-announce-list mailing list