【发布时间】:2019-06-27 09:44:36
【问题描述】:
我正在尝试将 in 的值添加到列表中。我需要使用 xpath 获取包含此值 new_values = ['a','b'] 的列表
import xml.etree.ElementTree as ET
parse = ET.parse('xml.xml')
[ record.find('events').text for record in parse.findall('.configuration/system/') ]
xml.xml 文件
<rpc-reply>
<configuration>
<system>
<preference>
<events>a</events>
<events>b</events>
</preference>
</system>
</configuration>
</rpc-reply>
我的 python 代码的输出是一个只有一个值的列表 - ['a'],但我需要一个带有 a 和 b 的列表。
【问题讨论】:
标签: python xml xpath xml-parsing xml.etree