我想选择一个没有作为其祖先的节点。你知道吗
例如
<root>
<e>
<head>
<id>3</id>
<word>abandon</word>
</head>
<body>
<head>
<word>accept</word>
</head>
</body>
</e>
</root>
我要选择第一个元素,而不是第二个元素。你知道吗
我试过:
import xml.etree.ElementTree as ET
root = ET.fromstring(fin).getroot()
word = root.find('.//word[not(ancestor::body)]')
但它不起作用。你知道吗
可以将XPath 1.0与lxml一起使用:
相关问题 更多 >
编程相关推荐