I am having a problem with my XML creator, I am generating a whole bunch of data based on objects coming in from Maya and it would be best if I could have my attribute keys generated in the file in the order they are written in rather than (very annoyingly) having them alphabetically ordered.
I populate my elements like so:
bodies = ET.SubElement(root, "bodies")
myRp = [ET.Element("object", name=str("rootPoint"))]
myBodies = [ET.Element("object", name=str(cObj), type=checkCollisionType(cObj), padding="-2.5") for cObj in cObjects]
bodies.extend(myRp)
bodies.extend(myBodies)
And I write them like so:
unformattedFile = ET.ElementTree(root)
unformattedFile.write(filePath)
prettyPrintXml(filePath)
My result should be something like this:
<body name="" enabled="" template="">
<object name="" />
<object name="" collision_type="" padding=""/>
</body>
But after it is written by element tree I get this:
<bodies>
<body enabled="" name="" template="">
<object name=""/>
<object name="" padding="" type=""/>
</bodies>
For readability and generality I would really like to preserve my original order. I found someones re-work of the ElementTree module but it messed up a lot of things
I have scoured the net and havent been able to find a viable solution yet.
Any help would be greatly appreciated.
Cheers