suggesting
s = '''
<book>
<title>My Book</title>
<author>John Smith</author>
</book>'''
The DOM will look like this:
from xml.dom import minidom
dom = minidom.parseString(s)
for author in dom.getElementsByTagName('author'):
author.childNodes = [dom.createTextNode("Jane Smith")]
But I would advise you to look into ElementTree, this will simplify the work with XML:
from xml.etree import ElementTree
et = ElementTree.fromstring(s)
for author in et.findall('author'):
author.text = "Jane Smith"
source
share