I would like to compare 2 xml and get a specific output, using Python.
example:
old.xml
<foos>
<foo>
<id>1</id>
<x>1</x>
</foo>
<foo>
<id>2</id>
<x>1</x>
</foo>
<foo>
<id>3</id>
<x>1</x>
<y>1</y>
</foo>
</foo>
new.xml
<foos>
<foo>
<id>1</id>
<x>2</x>
<y>1</y>
</foo>
<foo>
<id>2</id>
<x>1</x>
</foo>
<foo>
<id>3</id>
<x>2</x>
<y>1</y>
</foo>
<foo>
<id>4</id>
<x>1</x>
</foo>
</foo>
And the output I want:
output.xml
<foos>
<foo>
<id>1</id>
<x>2</x>
<y>1</y>
</foo>
<foo>
<id>3</id>
<x>2</x>
</foo>
<foo>
<id>4</id>
<x>1</x>
</foo>
</foo>
I wrote a very ugly function with poor performances, and I would like to find a better way to do that. Do you have any ideas of how to perform this task with good performances ?
Some issues I had ;
- ids lists of the 2 xml are not equals (objects can be deleted or added between the 2 xml)
- specific format of the output, prevents me using classic lib doing the job (https://github.com/Shoobx/xmldiff). But maybe there is a workaround ?
Maybe this is also an ugly method, for your information.