XML vs Python?
paul at boddie.net
Fri Jan 17 05:57:38 EST 2003
"N. Thomas" <nthomas at cise.ufl.edu> wrote in message news:<slrnb293jk.1hr.nthomas at rain.cise.ufl.edu>...
> ...or rather "XML's data structures vs Python's data structures"
> Are there any issues that I should be aware of regarding this? I mean,
> are there situations where is it better to save one's data in XML
> internally as opposed to using the language's native structures, and
> exporting to/from XML?
Before the XML heavyweights get in on this, I would make the following points:
* A lists and dictionaries approach certainly has its merits:
speed (at least according to the PyRXP people), familiarity,
interoperability with other Python stuff.
* Once you start to look into more advanced features, it would
seem to me that the lists and dictionaries model approaches
such a level of complexity that a "proper" object model would
be better. That is because you would need to find more
efficient ways (in terms of expression) of requesting an
attribute with a given namespace, for example, than examining
raw dictionaries. Certainly, it appears to me that...
attr = element.getAttributeNS(some_namespace, some_name)
...is more obvious than...
attr = element[some_namespace][some_name]
...especially if it's hidden in lots of heavy XML processing
* You could write your own object model. Frederik Lundh's
ElementTree is like this. I'm not 100% convinced that it's
beneficial to drop a standard object model that is widely
understood for another which is more Pythonic, although this
is a tradeoff that might be appropriate for some situations.
* If someone were to write an XPath wrapper for PyRXP and
similar packages, many standards issues would be less of a
concern. However, those wishing a "Pythonic" experience
arguably wouldn't benefit from XPath, and that experience
would obviously no longer be a motivation for XPath users
of such packages (since the nice Pythonic interface would
* If performance is a concern, libxml2 and cDomlette are
supposedly rather fast. I've never used the libxml2 bindings
for Python due to the lack of a PyXML-style DOM interface
until recently (I believe), but it's interesting that no
benchmark appears for it in the PyRXP benchmarks comparison
Anyway, I hope this helps.
More information about the Python-list