Python:使用 minidom 搜索具有特定文本的节点 [英] Python: Using minidom to search for nodes with a certain text

查看:25
本文介绍了Python:使用 minidom 搜索具有特定文本的节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前面临的 XML 如下所示:

I am currently faced with XML that looks like this:

<ID>345754</ID>

这包含在层次结构中.我已经解析了 xml,并希望通过搜索345754"来找到 ID 节点.

This is contained within a hierarchy. I have parsed the xml, and wish to find the ID node by searching on "345754".

推荐答案

xmldoc = minidom.parse('your.xml')
matchingNodes = [node for node in xmldoc.getElementsByTagName("id") if node.nodeValue == '345754']

另见:

这篇关于Python:使用 minidom 搜索具有特定文本的节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆