使用从xml解析属性名文本xml.etree.elementT文件

2024-06-17 18:41:43 发布

您现在位置:Python中文网/ 问答频道 /正文

我不确定如何使用以下代码从<array name="logEntries" type="value" depth="1">获取值。你知道吗

到目前为止,如果在xml上只有一个数组标记,而不是多个数组标记,那么我现在所拥有的是有效的。你知道吗

#Currently xml_input var is returned from an http request
root = ElementTree.fromstring(xml_input)
for child in root.findall('.array/value'):
    print(child)

XML示例:

<?xml version="1.0" encoding="UTF-8"?>
<Values version="2.0">
  <array name="logList" type="value" depth="1">
    <value>type_log</value>
  </array>
  <value name="numlines">2</value>
  <array name="numlinesList" type="value" depth="1">
    <value>2</value>
  </array>
  <array name="logEntries" type="value" depth="1">
    <value>some inputs</value>
    <value>other inputs</value>
  </array>
</Values>

期望输出:

some inputs
other inputs

简而言之,即使是咨询The ElementTree XML API我也无法发现如何克服这个问题。你知道吗

提前谢谢


Tags: name标记childinputvaluetyperoot数组