Tech Tips: DevTest Graphical XML Side-by-Side Comparison (XML Compare Options)

Document created by A_H Employee on Oct 27, 2015
Version 1Show Document
  • View in full screen mode

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.

 

in the "Ignored Nodes" setting of the XML side-by-side assertion, use an xpath that is independent from the index of your element. For example "//name" and also check the box "Ignore child element ordering".

On my instance (8.3), it works.

 

In the XML, right click on the node and select Ignore option. This will automatically  add XPath to the Ignore nodes.

 

To ignore the element text, click on the "Settings" tab and check the "Ignore element text" check box.

 

This document was generated from the following discussion: Tech Tips: DevTest Graphical XML Side-by-Side Comparison (XML Compare Options)

Attachments

    Outcomes