XPath, XML, Python

A discussion with some interesting views and perspective.

Here you'll find code snipptes showing the API of the various libraries (all of them used to solve the same programming task), and comments about the behaviour of each of the libraries.

I am not sure if this item should be categorized as being pro-libraries, pro-a big standard libary, or pro-builtin language support for XML.

You decide.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Python bindings

I've tended to use Python bindings to non-Python libraries for XML work: Pyana (which binds to Xalan-C++) for XSLT, libxml2 for DOM and SAX processing. I see that Pyana now has a sibling project, PIRXX, which aims to provide bindings for Xerces-C++.

XPath in particular is sufficiently complex that you do need a thorough implementation, which probably means a big library of some sort: the more lightweight and Pythonic solutions tend to have either incomplete or negligible XPath support.

I haven't looked at 4Suite for a while, as the last time I looked it didn't seem so easy to disengage the bits I wanted (SAX, DOM, XPath, XSLT) from the (doubtless very useful) bits I didn't (RDF support, XML repository, etc).

4Suite Amara looks like an interesting project, and a continuation of a well-tried approach - Python is already rich in tools providing binding of XML to native Python object trees, nested dictionaries etc., of which David Mertz's gnosis.xml is one of the more venerable. In a sense this is not so much built-in language support for XML as the language being sufficiently protean to glom onto XML, gloop around it and digest it slowly.