Python: xml.dom.minidom empty nodeValue non-empty value toxml ()

I have a line that gets nodeValue Node:

parent.getElementsByTagName("Url")[0].nodeValue

which returns nothing:

<br/>

When I do this:

parent.getElementsByTagName("Url")[0].toxml()

it returns:

< Url>www.something.com< /Url>

I'm not sure what is going on here. Another data point: when I do nodeName instead of nodeValue, it returns, as expected, Url.

Any thoughts?

+5
source share
2 answers

Try the following:

parent.getElementsByTagName('Url')[0].childNodes[0].nodeValue
+5
source

DOM Level 2 documentation states that nodeNamefor the node element is the name of the tag, nodeValuealways null, and attributes- this is NamedNodeMap, so that the code behaves as expected.

0
source

All Articles