[英]how to parse xml to get specific nodes having particular value for an attribute
[英]How to get value in nodes with specific attribute in XML by using python3?
我是Python初学者。 现在,我正在处理XML和xml.etree.ElementTree 。
我正在处理下面的示例xml,
<?xml version="1.0"?>
<data>
<country name="Liechtenstein">
<rank>1</rank>
<year>2008</year>
<gdppc>141100</gdppc>
<neighbor name="Austria" direction="E"/>
<neighbor name="Switzerland" direction="W"/>
</country>
<country name="Singapore">
<rank>4</rank>
<year>2011</year>
<gdppc>59900</gdppc>
<neighbor name="Malaysia" direction="N"/>
</country>
<country name="Panama">
<rank>68</rank>
<year>2011</year>
<gdppc>13600</gdppc>
<neighbor name="Costa Rica" direction="W"/>
<neighbor name="Colombia" direction="E"/>
</country>
</data>
我想使用特定属性在country标签内获取值。
例如,
我想获得国家名称=“新加坡”的排名,年份和gdppc
我尝试过,但不知道该怎么做。
是否有可能做到这一点?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.