tags:

views:

125

answers:

3

How can I make sure that my Python script, which will be doing some XML parsing, will Just Work with Python 2.4, 2.5 and 2.6?

Specifically, which (if any) XML parsing library is present in, and compatible between, all those versions?

Edit: the working-out-of-the-box requirement is in place because the XML parsing I'm going to need to do is very limited (just grabbing some values) and I'm going to need to run this script on a bunch of different platforms, so I'd rather deal with a crappy XML API then try to get lxml installed on Mac, Linux and Windows.

+1  A: 

You can use minidom

liza
+7  A: 

minidom is available in Python 2.0 and later.

However, if I were you, I would strongly consider using ElementTree which is available in Python 2.5 and later. Its syntax is much more pleasant.

2.4 users can reasonably easily download ElementTree, 2.5+ it will work without any additional dependencies. But I may be spoiled by rarely needing to target pre-2.5, myself.

Jeffrey Harris
I second the thought to use ElementTree. You could utilize it as a supplemental package to your script. Try to import ElementTree, if it throws an exception, import your private copy. This technique allows you to have the best of both worlds.
wlashell
+4  A: 

So, basically intersect the result of "xml" in these pages:

That leaves xml.dom and xml.sax.

If you could relieve the "out-of-the-box"-requirement: lxml

Alex Brasetvik
D'oh! Hadn't thought of doing that - thank.
David Wolever