伙计们! 我试图解析一些奇怪的XML格式:
<?xml version="1.0" encoding="UTF-8"?>
<analytics>
<standard1>
...
<attributes>
<attribute name="agentname" value="userx userx" />
<attribute name="agentpk" value="5" />
<attribute name="analytics:callid" value="757004000003597" />
...
<attribute name="wrapuptime" value="0" />
</attributes>
</standard1>
<standard2>
...
<attributes>
<attribute name="agentname" value="userx userx" />
<attribute name="agentpk" value="5" />
<attribute name="analytics:callid" value="757004000003597" />
...
<attribute name="wrapuptime" value="0" />
</attributes>
</standard2>
<engines>
...
</engines>
</analytics>
因为name和value都是属性,我不知道如何通过name访问value,而不必循环整个属性子段。在
你知道如何使用ElementTree直接访问吗?在
您可以使用一个简单的XPath表达式按
name
属性的值过滤attribute
元素。样本工作代码:印刷品:
^{pr2}$注意
xml.etree.ElementTree
有一个limited XPath support。在相关问题 更多 >
编程相关推荐