python xml version missing



i am using python xml to update some xml date i have small problem ,when i update the xml it cant write xml version this is my code



import xml.etree.ElementTree as ET
tree = ET.parse(r'c:\users\g\desktop\IT_ADMINVersionTrack.xml')
root = tree.getroot()

for country in root.findall('dtModule'):
f = country.find('FolderName').text
print "FOLDER:",f
v = country.find('Version').text
print "OLD VERSION:",v
if v == "11.0":
country.find('Version').text = "12.0"
v2 = country.find('Version').text
print "NEW VERSION",v2
else:
print "NO CHANGE IN VERSION"

tree.write(r'c:\users\g\desktop\output.xml')


input xml:



<?xml version="1.0"?>
output xml:
<dsModule>
<dtModule>
<ModuleName>IT_ADMIN</ModuleName>
<Version>11.0</Version>
<FolderName>IT_ADMIN\ItDataCompInterface.dll.gz</FolderName>
<Type>P</Type>
<ClientId />
<Destination />
</dtModule>
</dsModule>


output xml:



<dsModule>
<dtModule>
<ModuleName>IT_ADMIN</ModuleName>
<Version>12.0</Version>
<FolderName>IT_ADMIN\ItDataCompInterface.dll.gz</FolderName>
<Type>P</Type>
<ClientId />
<Destination />
</dtModule>
</dsModule>


xml version is missing


No comments:

Post a Comment