EaseXML: A Python Data-Binding Tool
EaseXML is an XML data-binding tool for Python, available under the Python Software Foundation License. The package used to be called "XMLObject," but that generic name led to the situation I mentioned in Location, Location, Location.
How many "XMLObjects" does it take to screw in a lightbulb? Turns out that even I, who make it my business to pay attention to such things, came up short in my count. Philippe Normand, author of one of the "XMLObjects," lamented the name clash after the latest entrant emerged. Srijit Kumar Bhadra, an innocent bystander (and author of the Python/.NET/XML code bake off I mentioned last month) also complained. The trigger for all this was Greg Luterman's announcement of XMLObject, "a Python module that simplifies the handling of XML streams by converting the data into objects." Of course, anyone who chooses as generic a name as "XMLObject" is just asking for name clashes.
Philippe Normand responded in a comment on that article that he
would be changing the name of his project. In this article, I'll look
at EaseXML 0.2, which
for installation on Python 2.4 (Python 2.2. is the minimum version).
The installation is standard distutils, a simple matter of
python setup.py install.
EaseXML at First Glance
In this column I have covered Python data bindings that need no more information than the source XML, such as Amara Bindery and Gnosis Objectify. I also introduced one example, generateDS.py, of a data binding that requires an XML schema file to drive the binding. EaseXML is similar to this latter approach, except that the schema format it uses is just a set of Python classes defined with a set of conventions, with each XML element generally corresponding to a distinct Python class. In this way it is very similar to XIST, although it's less comprehensive.
I'll start by showing the EaseXML binding schema used to process Listing 1, my usual address label example.Listing 1. Sample XML file (labels.xml) containing address labels
<?xml version="1.0" encoding="iso-8859-1"?> <labels> <label id="tse" added="2003-06-20"> <name>Thomas Eliot</name> <address> <street>3 Prufrock Lane</street> <city>Stamford</city> <state>CT</state> </address> <quote> <emph>Midwinter Spring</emph> is its own season… </quote> </label> <label id="ep" added="2003-06-10"> <name>Ezra Pound</name> <address> <street>45 Usura Place</street> <city>Hailey</city> <state>ID</state> </address> <quote> What thou lovest well remains, the rest is dross… </quote> </label> <!-- Throw in 10,000 more records just like this --> <label id="lh" added="2004-11-01"> <name>Langston Hughes</name> <address> <street>10 Bridge Tunnel</street> <city>Harlem</city> <state>NY</state> </address> </label> </labels>
Listing 2 (labelsease.py) uses the EaseXML conventions to set up the data binding.