Python updated xml file different form the original file

84 views Asked by At

So, I have an xml file and created a script in python to change some values, which works just fine but when I create the output.xml (xml with updated values), the schema changes. I want to keep the same schema and update the values.

my script.py

import xml.etree.ElementTree as ET

tree = ET.parse('file_to_be_updated.xml')
root = tree.getroot()

for entry in root.iter('tratamento'):
    current_text = entry.text.rstrip()
    entry.text = current_text + '_new'

tree.write('output.xml')

What I get:

Comparison between the two files

In this output file we missed the first line <?xml version = "1.0" encoding="Windows-1252" standalone="yes"?> and the xsd become xs in the schema.

Is there a way to generate an updated xml but keep everything else the same?

0

There are 0 answers