xml attributes question

Sylvain Thenault sylvain.thenault at nospam.logilab.fr
Mon Aug 16 04:25:22 EDT 2004


On Sun, 15 Aug 2004 12:25:58 +1000, Ajay wrote:

> hi!
> 
> i am trying to print the keys of a NamedNodeMap which contains the
> attributes of a element.
> for the element,
> <DATA ref="#business.name">CatalogExample</DATA>
> 
> i expect
> attribs = plist[0].attributes
> attribs.keys()
> to print "ref" #plist[0] is the data element shown above It however prints
> the following
> [(None, u'ref')]
> 
> why?

because of xml namespaces. Any xml element / attribute is fully
caracterized by it's name and the namespace it belongs to. None is used to
represent the empty namespace. With the following element :

<DATA xmlns:me="mynamespace" me:ref="#business.name">...</DATA>

your sample code would have printed :
 [(u'mynamespace', u'ref')]


-- 
Sylvain Thénault                               LOGILAB, Paris (France).

http://www.logilab.com   http://www.logilab.fr  http://www.logilab.org





More information about the Python-list mailing list