如何使用特定标签属性读取 python 中的 xml?
how to read xml in python with a specific tag attribute?
我有一个 xml 标签,我在 python 中使用下面的代码来读取这个标签,但我只想在 type = "Actual" 时获取数据,否则忽略。目前我得到了他们每个人的价值,即 40、50、60。
xml 标签:
<student type="Actual">40</student>
<student type="estimated">50</student>
<student>60</student>
Python代码:
student = root.find("./student")
请告知此语法中所需的更改。
您可以使用以下语法列出具有 "Actual type" 属性的所有节点:
students = root.findall('./student[@type="Actual"]')
我有一个 xml 标签,我在 python 中使用下面的代码来读取这个标签,但我只想在 type = "Actual" 时获取数据,否则忽略。目前我得到了他们每个人的价值,即 40、50、60。
xml 标签:
<student type="Actual">40</student>
<student type="estimated">50</student>
<student>60</student>
Python代码:
student = root.find("./student")
请告知此语法中所需的更改。
您可以使用以下语法列出具有 "Actual type" 属性的所有节点:
students = root.findall('./student[@type="Actual"]')