'Control attribute ordering with ElementTree
I am trying to compare two xml files, which have different formatting but similar content. The way I am going about this is:
- Parse XML files with
ElementTree - Pretty print the xml content, so that we get a normalized format. For this I am using either
ElementTree.tostringorElementTree.write - Now use any tool to compare the normalized files (textual comparisson)
This works fine, but a big problem remains: I am unable to control the order of the attributes in the nodes.
Is it possible to force a certain attribute sort order with ElementTree?
I do not want to keep the original attribute order, but provide a sort mechanism myself, so that, no matter how the original files look like, the normalized files will have the same attribute order.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
