Python xml.dom.minidom.Attr question

Getting attributes using minidom in Python, using the "attributes" property. egnode.attributes["id"].value

So, if I have <a id="foo"></a>, this should give me "foo". node.attributes["id"]does not return the value of a named attribute, but an instance xml.dom.minidom.Attr. But looking for help Attr, doing help('xml.dom.minidom.Attr'), this magic property is not mentioned anywhere "value". I like to learn APIs by looking at the type hierarchy, instance methods, etc. Where did this property come from "value"? Why is it not listed on the Attrclass page ? The only data descriptors specified are isId, localNameand schemaType. He was also not inherited from any superclasses. Since I'm new to Python, will any of the Python gurus enlighten?

+3
source share
2 answers

minidom- it's just the implementation of interfaces xml.dom, so any documents specifically related to the mini-minima, will concern only the features or limitations.

xml.domdocs on Attr say, and I quote:

Attr inherits from Node, so it inherits all of its attributes.

Documents Node actually called another attribute: nodeValue. But, really ...:

>>> import xml.dom.minidom as xdm
>>> dom = xdm.parseString('<foo bar="baz"/>')
>>> root = dom.documentElement
>>> atr = root.getAttributeNode('bar')
>>> atr.nodeValue
u'baz'

, nodeValue _un_documented value, , , , , nodeValue. , , minidom, , xml.etree.ElementTree ( C, xml.etree.cElementTree), , minidom, , ...; -).

+4

, . , node.value . , def __setitem__ xml.dom.minidom.

, , , .

0

Source: https://habr.com/ru/post/1744434/


All Articles