I am writing an XML comparison tool and need to ignore the object, rather than a property, order. For instance:
XML 1.
<Root>
<Vehicles>
<Vehicle>
<Registration>ABC123</Registration>
<Make>Ford</Make>
<Model>Focus</Model>
<Doors>4</Doors>
</Vehicle>
<Vehicle>
<Registration>DEF789</Registration>
<Make>BMW</Make>
<Model>330E</Model>
<Doors>4</Doors>
</Vehicle>
</Vehicles>
</Root>
XML 2.
<Root>
<Vehicles>
<Vehicle>
<Registration>DEF789</Registration>
<Make>BMW</Make>
<Model>330E</Model>
<Doors>4</Doors>
</Vehicle>
<Vehicle>
<Registration>ABC123</Registration>
<Make>Ford</Make>
<Model>Focus</Model>
<Doors>4</Doors>
</Vehicle>
</Vehicles>
</Root>
The order of the Vehicle objects is not important, so I want the above 2 XMLs to be deemed as matching ones.
However XmlUnit Diff returns mismatches for example it is comparing vehicle 0 on each side so diffs for reg ABC123 vs DEF789, make BMW vs Ford etc.
Found plenty of examples explaining how to ignore property order, but not how to match up objects before comparing properties. With some playing around I can match objects by a field for example by pairing up based on a Registration either side, however this one requires a method per a list of objects for example Registration for the above list of Vehicle, Forename for a driver collection and so on.
Hoping, there is a generic approach as these XMLs being compared relatively to insurance quote hub requests from aggregators and as such contain hundreds of collections which may be in different orders, for example collections of vehicles, drivers, claims, convictions, medical conditions, numerous enrichment score collections for credit scoring, fraud scoring, checking birth data and so on.
Any ideas?
I tried overriding DefaultNodeMatch without much luck.
Vehicleby it'sRegistrationvalue, or even just the computed string value of the element) and THEN diff those normalized docs.