python xml.dom.minidom 替换节点

原xml文件如下:


hello

需要把其中的:

替换为(新):

hi

将原xml文件存在xml.dom.minidom中,
dom_tree = xml.dom.minidom.parse("old_xml")
root = dom_tree.documentElement #节点
将新的xml存在xml.dom.minidom中,
dom_tree2 = xml.dom.minidom.parse("new_xml")
new_node = dom_tree2.documentElement
遍历root节点下的所有

,当div的name=tr,用new_node 替换当前找到的节点。
nodes= root .getElementsByTagName('div')
for node in nodes:
if node.hasAttribute("name"):
if node.getAttribute("name") == 'tr':

将node替换为new_node

请问xml中如何用dom替换节点,看了文档,没找到可以使用的方法。谢谢!

http://www.cnblogs.com/wcwnina/p/7222180.html