Search code examples
pythonxmlxpathxml.etree

Invalid Predicate using xml etree


iclasses = self.xml.getroot().find(".//iclass[((docvars/docvar[@key='isa' and @value='A32']) or (docvars/docvar[@key='isa' and @value='T32']))]")

File "/usr/lib64/python3.6/xml/etree/ElementPath.py", line 233, in prepare_predicate raise SyntaxError("invalid predicate") SyntaxError: invalid predicate make: *** [graphics] Error 1

Trying to fetch all iclasses where docvars/docvar[@key ='isa' and @value='A32']

Don't know what wrong i am doing


Solution

  • There seems nothing wrong with your XPath, but would simplify it to this:

    .//iclass[docvars/docvar[@key='isa'][@value[.='A32' or .='T32']]]