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 的值?
走同样的路,发现不同的人生