我正在使用python模块xml.dom.minidom
编辑XML。问题如下。当我使用writexml
更新我的XML文件时,它会从程序中删除空格,也会删除一些数据,例如它会自动从<?xml version="1.0" standalone="yes"?>
中删除standalone="yes"
。你知道吗
请帮我解决这个问题。这是我的密码:
from xml.dom.minidom import parse
import xml.dom.minidom
file_handle = open(r'c:\users\g\desktop\filename.xml',"wb")
DOMTree = xml.dom.minidom.parse(r'c:\users\g\desktop\IT_ADMINVersionTrack.xml')
collection = DOMTree.documentElement
movies = collection.getElementsByTagName("dtModule")
for movie in movies:
type2 = movie.getElementsByTagName('FolderName')[0]
print "Folder: %s" % type2.childNodes[0].data
type = movie.getElementsByTagName('Version')[0]
print "VERSION: %s" % type.childNodes[0].data
type = movie.getElementsByTagName('Version')[0]
type.childNodes[0].data = "12.15.0"
print "NEW VERSION: %s" % type.childNodes[0].data
DOMTree.writexml(file_handle)
目前没有回答
相关问题 更多 >
编程相关推荐