I’d like to select a node which doesn’t have as its ancestor.
for example,
<root>
<e>
<head>
<id>3</id>
<word>abandon</word>
</head>
<body>
<head>
<word>accept</word>
</head>
</body>
</e>
</root>
I want to select the first element, not second one.
I tried:
import xml.etree.ElementTree as ET
root = ET.fromstring(fin).getroot()
word = root.find('.//word[not(ancestor::body)]')
But it doesn’t work.
You can use XPath 1.0 with lxml: