在下面使用perl或python的xml中(这是最快的),我想要一种方法来获取attribute1设置为“characters”、attribute2没有设置为“chr”或attribute2本身没有的所有节点/节点名称。 请记住,我的xml可以有500个节点,所以请建议一种更快的方法来获取所有节点
<NODE attribute1="characters" attribute2="chr" name="node1">
<content>
value1
</content>
</NODE>
<NODE attribute1="camera" name="node2">
<content>
value2
</content>
</NODE>
<NODE attribute1="camera" attribute2="car" name="node3">
<content>
value2
</content>
</NODE>
您要查找的是xpath表达式:
使用xmllint进行快速测试:
更新
如果只想提取属性
name
的值,可以使用以下xpath://节点[@attribute1=“characters”和(不是(@attribute2)或@attribute2=“chr”)]/@name
或者 字符串(//节点[@attribute1=“characters”和(不是(@attribute2)或@attribute2=“chr”)]/@name)
仍使用xmllint进行测试:
在您将其标记为perl/python时,我将提供一种perlish方法。你知道吗
Perl有一个很好的库^{} ,我非常喜欢它来解析XML。你知道吗
使用
lxml
模块。你知道吗输出:
相关问题 更多 >
编程相关推荐