I have googled for this and I know there are like 10 other questions like this but I can't seem to get it to work..
I want to compare 2 xml strings and only get the differences in spelling errors or stuff like that, while ignoring child order. This is my code atm:
public void xmlCompare() {
try {
// First XML-read
InputStream is = new FileInputStream("xmlTestCorrect.xml");
String xmlText = IOUtils.toString(is);
// Second XML-read
InputStream is2 = new FileInputStream("xmlTestFalse.xml");
String xmlText2 = IOUtils.toString(is2);
Diff diff = DiffBuilder.compare(Input.fromString(xmlText)).withTest(Input.fromString(xmlText2))
.withNodeMatcher(new DefaultNodeMatcher(ElementSelectors.byName)).ignoreWhitespace()
.ignoreComments().checkForSimilar().build();
System.out.println(diff.hasDifferences());
System.out.println(diff.getDifferences());
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
And my result....
Expected text value 'commons-io' but was 'org.json'
Expected text value 'commons-io' but was 'json'
etc.. I have just switched around some dependencies in the xmlTestFalse.xml file (also added some spelling errors which successfully shows). And the switched dependencies are still noticed. Why?? I tried doing something like this since I have the same version of xmlunit: like this