Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/332.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 解析此xml文件的错误在哪里_Python_Xml_Python 2.7 - Fatal编程技术网

Python 解析此xml文件的错误在哪里

Python 解析此xml文件的错误在哪里,python,xml,python-2.7,Python,Xml,Python 2.7,这是我的xml文件: <Attributes> <Attribute> <name>action</name> </Attribute> <Attribute> <name>country</name> </Attribute> <Attribute> <name>city<

这是我的xml文件:

<Attributes>
    <Attribute>
        <name>action</name>
    </Attribute>
    <Attribute>
        <name>country</name>
    </Attribute>
    <Attribute>
        <name>city</name>
    </Attribute>
    <Attribute>
        <name>location</name>
    </Attribute>
    <Attribute>
        <name>ad_title</name>
    </Attribute>
    <Attribute>
        <name>posting_date</name>
    </Attribute>
    <Attribute>
        <name>bedrooms</name>
    </Attribute>
    <Attribute>
        <name>bathrooms</name>
    </Attribute>
    <Attribute>
        <name>type</name>
    </Attribute>
    <Attribute>
        <name>size</name>
    </Attribute>
    <Attribute>
        <name>property_referene</name>
    </Attribute>
    <Attribute>
        <name>price</name>
    </Attribute>
    <Attribute>
        <name>price_sqft</name>
    </Attribute>
    <Attribute>
        <name>building</name>
    </Attribute>
    <Attribute>
        <name>amenities</name>
    </Attribute>
    <Attribute>
        <name>description</name>
    </Attribute>
    <Attribute>
        <name>trade_name</name>
    </Attribute>
    <Attribute>
        <name>ded_licence_number</name>
    </Attribute>
    <Attribute>
        <name>rera_registration_number</name>
    </Attribute>
    <Attribute>
        <name>phone</name>
    </Attribute>
    <Attribute>
        <name>ad_images</name>
    </Attribute>
    <Attribute>
        <name>payment_type</name>
    </Attribute>
    <Attribute>
        <name>furnished</name>
    </Attribute>

</Attributes>

我一直认为getDefaultAttributes的数量为零,即使如您所见,属性太多了,请问我做错了什么?

使用您的示例文档:

>>> import lxml.etree
>>> et = lxml.etree.parse('test.xml')
>>> et.xpath('Attributes')
[]
>>> et.xpath('/Attributes')
[<Element Attributes at 0x10a55c7a0>]

…返回所有
属性
元素。

使用示例文档:

>>> import lxml.etree
>>> et = lxml.etree.parse('test.xml')
>>> et.xpath('Attributes')
[]
>>> et.xpath('/Attributes')
[<Element Attributes at 0x10a55c7a0>]

…返回所有
属性
元素。

使用示例文档:

>>> import lxml.etree
>>> et = lxml.etree.parse('test.xml')
>>> et.xpath('Attributes')
[]
>>> et.xpath('/Attributes')
[<Element Attributes at 0x10a55c7a0>]

…返回所有
属性
元素。

使用示例文档:

>>> import lxml.etree
>>> et = lxml.etree.parse('test.xml')
>>> et.xpath('Attributes')
[]
>>> et.xpath('/Attributes')
[<Element Attributes at 0x10a55c7a0>]
…返回所有
属性
元素