0

I have this xml:

<resources>
    <string name="name1">value1</string>
    <string name="name2">value2</string>
    <string name="name3">value3</string>
    <string name="name4">value4</string>
    <string name="name5">value5</string>
</resources>

and I want to change each value of each string tag, I've tried with ElementTree but i can not solve it...

I have this but it doesn't works!

tree = ET.parse(archivo_xml)
root = tree.getroot()
        
cadena = root.findall('string')
cadena.text = "something"
1
  • 2
    I have no experience whatsoever with XML in python but I would guess that root.findall() returns a list that you'd need to iterate over. Commented Nov 1, 2021 at 14:43

1 Answer 1

1

The root.findall() does return a list which is why that approach doesn't work.

Use root.iter() to find all the matching tags with 'string' instead, then loop over the results and change the text value of each.

for cadena in root.iter('string'):
    cadena.text = "something"
Sign up to request clarification or add additional context in comments.

Comments

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.