2
import xml.etree.ElementTree as ET
tree = ET.parse('test.xml')

xpathobjects = tree.findall(".//BuildingNodeBase[name = 'Building name']")

I am wanting to pull a BuildingNodeBase with a child tag name that has value Building name.

But Getting:

SyntaxError("invalid predicate")

2 Answers 2

3

The XPath support in ElementTree is limited, but your type of expression is supported. It's just that you need to remove the extra spaces around the =:

.//BuildingNodeBase[name='Building name']
0

I use lxml but I guess you can adopt this for your use:

from lxml import etree

tree = etree.parse('test.xml')

xpathobjects = tree.xpath(".//BuildingNodeBase[@name = 'Building name']")

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.