I'm trying to search a tag and replace an element in some XML code. Here is my attempt:
from xml.dom import minidom
dom = minidom.parse('../../../lib/config/folder/config.xml')
for tag_type in dom.getElementsByTagName('tag_type'):
tag_type.childNodes = [dom.createTextNode("Replacement Word")]
print tag_type
I'm running Python 2.4 so Element tree is not an option. Currently, I'm getting a response of:
<DOM Element: tag_type at 0x1c28a0e0>
Not sure why it isn't printing and not replacing.
childNodes. You must use the DOM methods to manipulate the tree.print tag_typewould print. What did you expect?