如何从box子元素访问Car。我能够获得属性名,但要获得Car,需要面对问题
<annotations>
<image height="940" id="0" name="90.jpg" width="1820">
<box label="Objects" occluded="1" xbr="255" xtl="0" ybr="624" ytl="509">
<attribute name="Class">Car</attribute>
<attribute name="Occlusion %">25-50%</attribute>
<attribute name="Truncation %">0%</attribute>
</box>
</image>
</annotations>发布于 2020-03-14 10:17:27
见下文
import xml.etree.ElementTree as ET
xml = '''<annotations>
<image height="940" id="0" name="90.jpg" width="1820">
<box label="Objects" occluded="1" xbr="255" xtl="0" ybr="624" ytl="509">
<attribute name="Class">Car</attribute>
<attribute name="Occlusion %">25-50%</attribute>
<attribute name="Truncation %">0%</attribute>
</box>
</image>
</annotations>'''
#
# Find the attribute element (under box element) where the attribute name value is 'Class'. print the text of the element text
#
root = ET.fromstring(xml)
print(root.find(".//box/attribute[@name='Class']").text)https://stackoverflow.com/questions/60681467
复制相似问题