xml in python

Piet van Oostrum piet at cs.uu.nl
Sun May 10 03:24:36 EDT 2009


>>>>> Shawn Milochik <Shawn at Milochik.com> (SM) wrote:

>SM> On Fri, May 8, 2009 at 3:46 AM, Rustom Mody <rustompmody at gmail.com> wrote:
>>> Can someone give me a heads up on xml parsing in python?
>>> The context is that I want to write a simple docbook to text converter.
>>> DOM is alright -- dont want to break my head with SAX just for performance
>>> when my documents are not likely to be large.
>>> 
>>> My problem is that there seems to be so many nearly equivalent ways (Pyxml?
>>> Amara?) some of which have moved from 3rd party to builtin status that I am
>>> not clear what is the current method of choice.
>>> 
>>> Thanks
>>> --

>SM> I've been using minidom for simple XML processing with success. The
>SM> XML module seems to be the way to go, considering how many of its
>SM> child modules are listed on http://docs.python.org/library/.

>SM> import xml.dom.minidom as minidom

These days ElementTree is considered the most pythonic way.
http://docs.python.org/library/xml.etree.elementtree.html

There is also a reimplementation of the ElementTree API based on libxml2
and libxslt, which has more features but requires a separate install. It
is largely compatible with ElementTree, however.
-- 
Piet van Oostrum <piet at cs.uu.nl>
URL: http://pietvanoostrum.com [PGP 8DAE142BE17999C4]
Private email: piet at vanoostrum.org



More information about the Python-list mailing list