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

时间:2022-01-12 22:38:32

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

我有一行获取Node的nodeValue:

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.

我不确定这里发生了什么。另一个数据点:当我执行nodeName而不是nodeValue时,它会按预期返回Url。

Any thoughts?

有什么想法吗?

2 个解决方案

#1


5  

Try this:

尝试这个:

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

#2


0  

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.

DOM Level 2文档声明元素节点的nodeName是标记名称,nodeValue始终为null,属性是NamedNodeMap,因此此代码按预期运行。

#1


5  

Try this:

尝试这个:

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

#2


0  

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.

DOM Level 2文档声明元素节点的nodeName是标记名称,nodeValue始终为null,属性是NamedNodeMap,因此此代码按预期运行。