0

我将如何使用解析以下区域值lxml

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<mstns:NewDataSet xmlns:mstns="AscentMetadataReport" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <mstns:Report>
        <mstns:Metadata>
            <mstns:Detail_Collection>
                <mstns:Detail>
                    <mstns:Territory>ARGENTINA</mstns:Territory>

这是我尝试过的:

node=etree.fromstring(contents)
territory = node.find('NewDataSet/Report/Metadata/Detail_collection/Detail/Territory')

尽管上述方法不起作用。我将如何解析这里的领土?

4

1 回答 1

0

在此处使用命名空间:

http://lxml.de/tutorial.html#namespaces

territory = node.find('mstns:ISOCountry',namespaces={'mstns':'AscentMetadataReport'}).text
于 2013-02-14T23:56:15.210 回答