Here is my code and XML:
xml_string = """
<data>
<user>
<name>123</name>
</user>
<user>
<name>456</name>
</user>
</data>
"""
import xml.etree.ElementTree as ET
root = ET.fromstring(xml_string)
I'm trying to find <user>
tag where <name>
has text value equal to 123.
What I have tried:
result = root.findall("./user[name = '123']")
result = root.findall("./user[./name = '123']")
result = root.findall("./user[/name = '123']")
result = root.findall("./user[./name text() = '123']")
None of these attempts worked. What am I missing?
Error I'm getting:
raise SyntaxError("invalid predicate")
File "<string>", line None
SyntaxError: invalid predicate