Reading XML namespaces

Stefan Behnel stefan_ml at behnel.de
Sun May 16 02:59:38 EDT 2010


Adam Tauno Williams, 16.05.2010 06:00:
> 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.

In order to find out which prefixes are used in the document and which set 
of namespace URIs each of them is mapped to, you need to traverse the 
entire document and aggregate all namespace definitions on all Elements. 
However, the result will be mostly useless, as a prefix is only meaningful 
within the scope of its definition. It doesn't have any sensible meaning 
for the entire document.

Stefan




More information about the Python-list mailing list