xml attributes question

Andrew Clover and-google at doxdesk.com
Sun Aug 15 05:30:22 EDT 2004


Ajay <abra9823 at mail.usyd.edu.au> wrote:

> attribs.keys()

> [(None, u'ref')]

> why?

Namespace-aware DOM implementations index attributes by the localName
*and* their namespaceURI. The 'ref' attribute isn't in a namespace
(signified by 'None') so this should be part of the key to support eg.
getAttributeNS efficiently.

Don't rely on the Python-style dictionary methods like keys() when you
are handling a NamedNodeMap. The Python DOM bindings do not guarantee
that it exists, or what it returns if it does. 4DOM behaves
differently to minidom as you can see; other implementations are
different again. Further, the results of keys(), values() and items()
are inconsistent even within single implementations.

Sticking to the standard DOM methods, one could say:

  keys= [attribs.item(i).name for i in range(attribs.length)]

-- 
Andrew Clover
mailto:and at doxdesk.com
http://www.doxdesk.com/



More information about the Python-list mailing list