我正在使用特定于服务器的数据,并希望解析xml文件中的数据“measTypes”。由于我的xml文件(名称空间)中有一些头数据,我无法解析数据,代码也失败了,您能帮我在xml数据中提取“measTypes”吗?你知道吗
我正在使用以下代码,但它失败了,因为measInfo没有值:
from lxml import etree
tree = etree.parse(open("BLRNCH03.xml"))
measInfo = tree.xpath('//measInfo[@measInfoId="67109488"]')[0]
print(measInfo)
以下是我的xml数据:
<?xml version="1.0" encoding="UTF-8"?>
<measCollecFile xmlns="http://latest/nmc-omc/cmNrm.doc#measCollec" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://latest/nmc-omc/cmNrm.doc#measCollec schema\pmResultSchedule.xsd">
<fileHeader fileFormatVersion="32.435 V7.2" vendorName="Huawei">
<fileSender elementType="BSC6910 UMTS"/>
<measCollec beginTime="2018-04-22T00:00:00+04:30"/>
</fileHeader>
<measData>
<measInfo measInfoId="67109481">
<measTypes>67194793 67194794 67194795 67194796 </measTypes>
</measInfo>
<measData>
<fileFooter>
<measCollec endTime="2018-04-22T01:00:00+04:30"/>
</fileFooter>
</measCollecFile>
只需bind the default namespace to a prefix并在
.xpath()
调用中使用它。你知道吗我使用了前缀
mc
,但是您可以使用不同的前缀。你知道吗示例。。。你知道吗
这将打印如下内容:
相关问题 更多 >
编程相关推荐