python - XML携带xmlns 命名空间时如何提取子节点值?
怪我咯
怪我咯 2017-04-18 10:20:59
0
0
683

test.xml

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<raml xmlns="raml21.xsd" version="2.1">
    <cmData type="actual">
        <header>
            <log dateTime="Fri Dec 16 15:40:00 +0800 2016" action=""/>
        </header>
        <managedObject class="BTSMED" distName="/BTSMED-1">
            <p name="btsmedID">1</p>
        </managedObject>
        <managedObject class="SW_UNIT_I" distName="/BTSMED-1/NE_CONF_I-1/BUILD_DATA_I-1/SW_UNIT_I-1">
            <p name="unitName">btsmed-1</p>
            
            <p name="version">BtsmedVersion</p>

        </managedObject>
    </cmData>
</raml>

使用

 for _, element in etree.iterparse('test.xml',tag='managedObject '):
    print element.findtext('p') 

结果:

如何获取节点 里的 BtsmedVersion 的值?

怪我咯
怪我咯

走同样的路,发现不同的人生

membalas semua(0)
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan