Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 解析除某些属性值之外的浮动和返回路径_Python_Xml_Parsing_Attributes - Fatal编程技术网

Python 解析除某些属性值之外的浮动和返回路径

Python 解析除某些属性值之外的浮动和返回路径,python,xml,parsing,attributes,Python,Xml,Parsing,Attributes,我试图解析深度嵌套的XML文件的浮动,并返回该节点的路径(某些属性值除外)。例如,给定下面的文件,我希望返回所有浮动,但不包括某些属性,如month=05和month=06 <data> <country name="Liechtenstein"> <rank updated="yes">2</rank> <language>english</language> <currency>1.2

我试图解析深度嵌套的XML文件的浮动,并返回该节点的路径(某些属性值除外)。例如,给定下面的文件,我希望返回所有浮动,但不包括某些属性,如month=05和month=06

<data>
<country name="Liechtenstein">
    <rank updated="yes">2</rank>
    <language>english</language>
    <currency>1.21$/kg</currency> 
    <gdppc month="06">141100</gdppc>
    <gdpnp month="10">2.304e+0150</gdpnp>
    <neighbor name="Austria" direction="E"/>
    <neighbor name="Switzerland" direction="W"/>
</country>
<country name="Singapore">
    <rank updated="yes">5</rank>
    <language>english</language>
    <currency>4.1$/kg</currency> 
    <gdppc month="05">59900</gdppc>
    <gdpnp month="08">5.2e-015</gdpnp>
    <neighbor name="Malaysia" direction="N"/>
</country>

如何将属性限制添加到此项?当我将[“05”、“06”]中的
node.attrib[“month”]添加到except函数时,它不起作用。如果有任何帮助,我将不胜感激。

我想你就快到了

如果您添加:

if 'month' in node.attrib:
    if node.attrib['month'] in ['05', '06']:
        return nums
就在
nums=[]
行之后,它应该完全按照您的要求执行。 在执行
extend

if 'month' in node.attrib:
    if node.attrib['month'] in ['05', '06']:
        return nums