Given the following XML (fragment):
<node id="b071f9fa-14b0-4217-8e97-eb41da73f598" type="Group" ext:score="90">
<node id="b071f9fa-14b0-4217-8e97-eb41da73f599" type="Person" ext:score="100">
<node id="b071f9fa-14b0-4217-8e97-eb41da73f600" type="Business" ext:score="80">
I want to retrieve the id
of nodes that have an ext:score
of 100.
The current code:
match = dom.xpath('//node[@ext:score="100"]/@id')[0]
Returns an exception:
lxml.etree.XPathEvalError: Undefined namespace prefix
I have read (both here and in XPath docs) that ext
would first need to be defined as a valid namespace, as the DOM cannot be parsed as an attribute if it contains special characters. However, I have been unable to find a good example of how to do this. There is no definition of ext
in the excerpts I am processing and I'm not sure how to create a namespace prefix
.
Any thoughts?