Question:
For XML Compare Options, how would one ignore the element itself? I have an 'optional' element, and if it's not there, it's fine, however ignore nodes seems to only ignore the contents of an element, not an element itself.
Answer:
Using the following 2 simple XMLs to explain:
XML A:
<?xml version="1.0" encoding="UTF-8"?>
<shipto>
<name>Ola Nordmann</name>
<address>Langgt 23</address>
<city>4000 Stavanger</city>
</shipto>
XML B:
<?xml version="1.0" encoding="UTF-8"?>
<shipto>
<address>Langgt 23</address>
<city>4000 Stavanger</city>
</shipto>
The difference between them is that the name element is missing in XML B.
When the name element is marked to be ignored, the existing source code handles it properly and ignores the element.
However another compare option, "Ignore child element ordering", seems to be interfering.
By default, this option is turned off, so the ordering (i.e. indexes) of element’s children is enforced.
In he above example, the index of the address element in XML A is 1, but it’s 0 in XML B because the name element is missing. As such the compare fails.
Note that this means that ordering would no longer be considered, but if an element is optional as in this case, the ordering would not match anyway.