Reputation: 1289
I'm trying to use XMLUnit to diff just the overall structure (no text/attributes) of two XML documents as follows with XMLUnit:
private static final String XML_HEADER = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
xhtml1 = XML_HEADER + "<b>Text</b>";
xhtml2 = XML_HEADER + "<b>Different Text!</b>";
Diff d = new Diff(xhtml1.trim(), xhtml2.trim());
DetailedDiff dd = new DetailedDiff(d);
dd.overrideElementQualifier(null);
dd.overrideDifferenceListener(new IgnoreTextAndAttributeValuesDifferenceListener());
List<Difference> l = dd.getAllDifferences();
for (Difference difference : l) {
System.out.println(d.toString());
}
Despite the fact that I override the difference listener on the DetailedDiff, I still get the following result:
org.custommonkey.xmlunit.Diff
[not identical] Expected text value 'Text' but was 'Different Text!' - comparing <b ...>Text</b> at /b[1]/text()[1] to <b ...>Different Text!</b> at /b[1]/text()[1]
Does DifferenceListener not apply to getAllDifferences? And if so, is there another way to diff only tags?
Upvotes: 2
Views: 616
Reputation:
IgnoreTextAndAttributeValuesDifferenceListener
downgrades the differences to "similar" not "identical", that's why they still show up in the list of Differences.
If you cannot live with "not identical" you'll need to use a DifferenceListener
of your own - and will likely end up copying IgnoreTextAndAttributeValuesDifferenceListener
changing just a single line.
Upvotes: 1