2
考慮下面的XML:如何替換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)
但是,在這種情況下,我不知道該值是多少。
是否有R基礎解決方案? – RanonKahn