Python: Parse XML file and change some values



I have to parse a xml document and to change some values. Here is the xml code:



<?xml version="1.0" encoding="utf-8"?>
<Node SchemaVersion="1.1" xmlns="www.somewebsite.com">
<Description>
<Name>This is the name</Name>
<ID>113213</ID>
</Description>
</Node>


I want to change the ID. Here is the Python code:



ns = {'ns': 'www.somewebsite.com'}
tree = ET.parse(xmlFile)
root = tree.getroot()

node = root.find('ns:Description', namespaces=ns).find('ns:ID', namespaces=ns)
node.text = 555

tree.write(xmlFile)


The problem is that the output xml is wrong



<ns0:AxeJobManifest xmlns:ns0="http://ift.tt/1pWfZs2" xmlns:ns1="http://ift.tt/1pWfYo6" xmlns:ns3="http://ift.tt/1pWfZs6" xmlns:xsi="http://ift.tt/ra1lAU" SchemaVersion="1.1">
<ns0:Description>
<ns0:Name>this is the name</ns0:ProgrammaticName>
<ns0:ID>5555</ns0:ID>
</ns0:Description>


How can i fix the problem?


No comments:

Post a Comment