[XML-SIG] libxml python bindings and other python DOM's

paul.boddie at ementor.no paul.boddie at ementor.no
Fri Jul 25 18:10:18 EDT 2003


Daniel Veillard [mailto:veillard at redhat.com] wrote:
> 
>   libxml2 tree support only generate nodes for namespace declarations.
> It does not generate equivalent attribute node. When an attribute or an
> element uses a namespace there is a reference to the associated
> namespace declaration.

This didn't affect me, though. I would have to look at the exact problem
that I experienced to be able to comment thoroughly, I'm afraid. However, it
could be that I just didn't understand the API well enough, since I managed
to try out some code which did exactly what I had in mind (and what I
thought might have been the problem).

For example:

>>> s = """<?xml version='1.0' encoding='US-ASCII'?><test:element xmlns:test="http://www.test.org"><test:another test:attr="horse"/></test:element>"""
>>> from xml.dom.minidom import parseString
>>> from libxml2 import parseDoc
>>> doc = parseDoc(s)
>>> doc2 = parseString(s)
>>> doc.children.children.nsProp("attr", "http://www.test.org")
'horse'
>>> doc2.childNodes[0].childNodes[0].getAttributeNS("http://www.test.org", "attr")
u'horse'
>>> doc.children.children.ns().content
'http://www.test.org'
>>> doc2.childNodes[0].childNodes[0].namespaceURI
u'http://www.test.org'

I don't believe that I have much more sophisticated usage of namespaces than
that. The only other exotic thing that caused me DOM portability issues was
importNode, so that might be something to consider (ie. how it is done with
the libxml2 API).

Anyway, I'll try and take a look at all this and report back later, because
libxml2 seems to be widely deployed/available and fast. Getting some level
of XPath API unification would also be rather nice.

Paul



More information about the XML-SIG mailing list