0

I'm not sure how i could get the values from <array name="logEntries" type="value" depth="1"> with the following code.

What i currently have so far, which works if have only one array tag on the xml, but not on multiple.

#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 sample:

<?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>

Desired output:

some inputs
other inputs

In short, even consulting The ElementTree XML API i'm unable to discover how can overcome this.

Thanks in advance

1
  • Works for me. I get all 4 <value>s. Commented Jun 8, 2016 at 17:29

1 Answer 1

2

Try this:

for child in root.findall('.//array[@name="logEntries"]/value'):
    print(child.text)
Sign up to request clarification or add additional context in comments.

1 Comment

Worked perfectly.Thank you!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.