I am using python beautiful soup to parse an XML file and write it to a different file after deletion of certain tags. But, using soup.prettify changes other XML namespaces and attribute names.
f = open('new.xml',"w"); f.write(soup.prettify(formatter="xml")); f.close();
The changes are as given in sample below.
Original XML file.
<draw:control text:anchor-type="paragraph" draw:z-index="1" draw:style-name="gr1" draw:text-style-name="P2" svg:width="2.805cm" svg:height="1.853cm" svg:x="3.602cm" svg:y="0.824cm" draw:control="control2"/>
New XML file written from soup.prettify.
<draw:control draw:control="control2" draw:style-name="gr1" draw:text-style-name="P2" draw:z-index="1" svg:height="1.853cm" svg:width="2.805cm" svg:x="3.602cm" svg:y="0.824cm" text:anchor-type="paragraph"/>
I tried adding utf-8 to prettify(). But, its the same problem. Is there any other method to delete a particular tag based on searching and keep all the other XML contents in the file in tact? Please suggest.