I have to parse xml files which contain entries like
<error code="UnknownDevice">
<description />
</error>
which are defined elsewhere as
<group name="error definitions">
<errordef id="0x11" name="UnknownDevice">
<description>Indicated device is unknown</description>
</errordef>
...
</group>
given
import xml.etree.ElementTree as ET
parser = ET.XMLParser()
parser.parser.UseForeignDTD(True)
tree = ET.parse(inputFileName, parser=parser)
root = tree.getroot()
How can I get those values for errorDef? I mean the value of id and of description?
How can I search for & extract those values, using unknownDevice?
[Update] The error groups have differing names, but always of the format "XXX error definitions", "YYY error definitions", etc
Further, they seem to be nested at different depths in different documents.
Given the error's title, e.g "unknownDevice", how can I search everything under the root to get the corresponding id and description values?
Can I go directly to them, using e.g "unknownDevice", or do I have to search first for the error groups?
xpathmethod, available in lxml but not in the std lib ElementTree module).ETis. Thanks for pointing that out.