python xpath in xml.etree.ElementTree



我将xml.etree.ElementTree与函数root.findall(xpath)一起使用如何找到所有具有"状态"子项且文本为"通过"的根的子项?

<Root>
<Some_Element> <!-- I want only this element -->
<Status>Pass</Status>
</Some_Element>
<Some_Element>
<Status>Fail</Status>
</Some_Element>
</Root>

感谢

尝试类似的东西

elements = [x for x in root.findall("Some_Element") if x.find("Status").text == "Pass"]

最新更新