0

Are those two roots the same??

Output xml got changed about the order in the root.

If they are different each other, how could I fix it??

#Python 3.7
import xml.etree.ElementTree as ET

ET.register_namespace('xsi', "http://www.w3.org/2001/test")
ET.register_namespace('', "http://www.test.com/test/test/test")
tree = ET.parse('test.xml')

tree.write("test1.xml", encoding='utf-8', xml_declaration=True)

#input XML root
<root xmlns:xsi="http://www.w3.org/2001/test" schemaVersion="2.8" xmlns="http://www.test.com/test/test/test" labelVersion="1" xsi:schemaLocation="http://www.test.com/test/test/test ..\Schema\CLIFSchema.xsd" name="test.xml">

#output XML root
<root xmlns="http://www.test.com/test/test/test" xmlns:xsi="http://www.w3.org/2001/test" labelVersion="1" name="test.xml" schemaVersion="2.8" xsi:schemaLocation="http://www.test.com/test/test/test ..\Schema\CLIFSchema.xsd">
Chang
  • 1
  • 1
  • Yes, those root elements are "the same". The order of attributes and namespace declarations should not matter. – mzjn May 22 '22 at 15:08
  • That's a relief... then can I ask why the order got changed?? – Chang May 22 '22 at 15:14
  • The order is not significant. You should not care about it. See https://stackoverflow.com/a/51234813/407651 – mzjn May 22 '22 at 15:16
  • You might want to test with Python 3.8 or later. See https://stackoverflow.com/a/60176826/407651 – mzjn May 22 '22 at 15:20

0 Answers0