给定以下xml:
<!-- file.xml -->
<video>
<original_spoken_locale>en-US</original_spoken_locale>
<another_tag>somevalue</another_tag>
</video>
<original_spoken_locale>
替换标签内的值的最佳方法是什么?如果我确实知道价值,我可以使用类似的东西:
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)
但是,在这种情况下,我不知道值是多少。