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.
Python allows parsing these XML documents using two modules namely, the xml. etree. ElementTree module and Minidom (Minimal DOM Implementation).
To read an XML file using ElementTree, firstly, we import the ElementTree class found inside xml library, under the name ET (common convension). Then passed the filename of the xml file to the ElementTree. parse() method, to enable parsing of our xml file. Then got the root (parent tag) of our xml file using getroot().
Extensible Markup Language (XML) is a markup language which encodes documents by defining a set of rules in both machine-readable and human-readable format. Extended from SGML (Standard Generalized Markup Language), it lets us describe the structure of the document. In XML, we can define custom tags.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With