Python:xml.dom.minidom 空 nodeValue 非空 toxml() 值

发布于 2024-08-19 05:14:45 字数 406 浏览 4 评论 0原文

我有一行获取节点的 nodeValue:

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

不返回任何内容:

<br/>

当我这样做时:

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

它返回:

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

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

有什么想法吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

£噩梦荏苒 2024-08-26 05:14:45

试试这个:

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

Try this:

parent.getElementsByTagName('Url')[0].childNodes[0].nodeValue
像极了他 2024-08-26 05:14:45

DOM Level 2 文档指出元素节点的 nodeName 是标签名称,nodeValue 始终为 null 并且 attributesNamedNodeMap,因此此代码的行为符合预期。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文