tom
tom

Reputation: 620

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

I have a line that gets the nodeValue of a Node:

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

that returns nothing:

<br/>

When I do:

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

it returns:

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

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

Any thoughts?

Upvotes: 7

Views: 4809

Answers (2)

Attila O.
Attila O.

Reputation: 16625

Try this:

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

Upvotes: 7

Torsten Marek
Torsten Marek

Reputation: 86652

The DOM Level 2 documentation states that nodeName for an element node is the tag name, the nodeValue is always null and attributes is a NamedNodeMap, so this code behaves as expected.

Upvotes: 0

Related Questions