Reading XML namespaces

Adam Tauno Williams awilliam at whitemice.org
Sun May 16 00:00:59 EDT 2010


On Sat, 2010-05-15 at 23:37 +0200, Martin v. Loewis wrote:
> > BTW, I'm still not sure I understand your problem. Could you provide
> > some more details?
> Wouldn't it be easier if you told the OP how to access the prefix

:)

> mappings in lxml etree, or, if this was actually not possible, admitted
> that it is actually not possible?

I suspect that it is not;  but that seems rather surprising. 

> FWIW, in the DOM, you look at all attributes of an element node, and
> search for those whose namespace is "http://www.w3.org/2000/xmlns/"
> In SAX, you watch the startPrefixMapping events.

Given that XML documents can be very large I'd rather avoid a parsing of
the document [beyond what lxml/etree] has already done] just to retrieve
the namespaces and their prefixes.




More information about the Python-list mailing list