[XML-SIG] Writing DOM-neutral code

Martin v. Loewis martin@v.loewis.de
Wed, 5 Dec 2001 23:35:17 +0100


> If I have an element, e, then
> 	Using pyxml (4dom) dom, e.attributes is a list

No, it is not. It is an NamedNodeMap, just as specified in

http://www.w3.org/TR/DOM-Level-2-Core/core.html#ID-1780488922

It is also a NamedNodeMap in minidom. So formally, you ought to use
.length and .item(index) (all other accessors are DOM level 2).


> 	Using cDomlette, e.attributes is a dictionary;
> 		e.attributes.values() is what is needed

Indeed. Notice that the Python DOM permits dictionary access to the
attributes through the dictionary interface, see

http://www.python.org/doc/current/lib/dom-attributelist-objects.html

Both minidom and 4DOM support this as well. 4DOM, in addition,
supports a sequence interface on .attributes.

> Anyone have any general approaches to this?  

Use the dictionary interface.

Regards,
Martin