Note that there are some explanatory texts on larger screens.

plurals
  1. POFind missing elements using XMLUnit
    primarykey
    data
    text
    <p><br/> I have the following testXML</p> <pre><code>&lt;root&gt; &lt;a&gt;test&lt;/a&gt; &lt;b&gt;bee&lt;/b&gt; &lt;d/&gt; &lt;/root&gt; </code></pre> <p>While the templateXML looks like this</p> <pre><code>&lt;root&gt; &lt;a/&gt; &lt;b/&gt; &lt;c/&gt; &lt;d&gt; &lt;e/&gt; &lt;/d&gt; &lt;/root&gt; </code></pre> <p>I want XMLUnit to return the missing elements, in this case 'c' and 'e' are missing</p> <p><b>/root[1]/c[1] is missing<br/> /root[1]/d[1]/e[1] is missing</b></p> <p>My code looks like this</p> <pre><code>public static ArrayList&lt;Difference&gt; testCompareToSkeletonXML(String xml, String template) throws Exception { XMLUnit.setCompareUnmatched(false); XMLUnit.setIgnoreAttributeOrder(true); XMLUnit.setIgnoreComments(true); XMLUnit.setIgnoreWhitespace(true); XMLUnit.setIgnoreDiffBetweenTextAndCDATA(true); DifferenceListener myDifferenceListener = new IgnoreTextAndAttributeValuesDifferenceListener(); DetailedDiff myDiff = new DetailedDiff(new Diff(template, xml)); // myDiff.overrideDifferenceListener(myDifferenceListener); myDiff.overrideElementQualifier(new RecursiveElementNameAndTextQualifier()); ArrayList&lt;Difference&gt; returnList = new ArrayList&lt;Difference&gt;(); List&lt;Object&gt; allDifferences = myDiff.getAllDifferences(); for(Object obj: allDifferences){ Difference dif = (Difference) obj; if(dif.getTestNodeDetail().getNode()== null){ //returnList.add(dif); System.out.println(dif.getControlNodeDetail().getXpathLocation()); } } return returnList; } </code></pre> <p>The output generated looks like this</p> <p>/root[1]/a[1] <br/> /root[1]/b[1] <br/> /root[1]/c[1] <br/> /root[1]/d[1] <br/></p> <p>Thanks for the help <br/> --SD</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload