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 に答える