[XML-SIG] PyXML and DOM example 'generate_xml1.py'

Fredrik Lundh fredrik at pythonware.com
Sun Sep 14 13:35:53 CEST 2008

David Lucena wrote:

> I've started to use PyXML because I needed a xml library for
 > a tool I am making.

if you're writing new code, I strongly suggest using a library based on 
the ElementTree API instead of struggling with an old, unmaintained and 
rather unwieldy XML library.

if I'm reading things correctly, your entire example boils down to

     import xml.etree.ElementTree as ET

     elem = ET.Element("spam", eggs="sunny side up")
     elem.text = "some text here..."

     print ET.tostring(elem)

with the ET API.

The standard implementation of ET is included in Python 2.5 and later:


and is available for Python 1.5.2 and newer from here:


and there's also a separate implementation based on the libxml2 and 
libxslt libraries, which adds validation and lots of other goodies:



More information about the XML-SIG mailing list