How to replace the text inside an XML element?

samarasz

New Member
Given the following xml:\[code\]<!-- file.xml --><video> <original_spoken_locale>en-US</original_spoken_locale> <another_tag>somevalue</another_tag></video>\[/code\]What would be the best way to replace the value inside of the \[code\]<original_spoken_locale>\[/code\] tag? If I did know the value, I could use something like:\[code\]with open('file.xml', 'r') as file: contents = file.read()new_contents = contents.replace('en-US, 'new-value')with open('file.xml', 'w') as file: file.write(new_contents)\[/code\]However, in this case, I don't know what the value will be.
 
Back
Top