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']
Sign up to request clarification or add additional context in comments.

Comments

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']")

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.