I'm trying to do matching where the element order of elements with different names may vary. In xmlunit 1 I used RecursiveElementNameAndTextQualifier, perhaps wrongly. In xmlunit 2, I thought the user guide is saying that ByNameAndTextRecSelector should work analogously, but I'm not successful. Here's a short test. Am I reading the user guide wrong, or perhaps it could use a clarification?
import java.io.IOException;
import org.custommonkey.xmlunit.examples.RecursiveElementNameAndTextQualifier;
import org.xml.sax.SAXException;
import org.xmlunit.builder.DiffBuilder;
import org.xmlunit.builder.Input;
import org.xmlunit.diff.ByNameAndTextRecSelector;
import org.xmlunit.diff.DefaultNodeMatcher;
public class Test {
public static void main(String[] args) throws SAXException, IOException {
final String xml1 = "<root><a/><b/></root>";
final String xml2 = "<root><b/><a/></root>"; // Flip <a/> and <b/>
// xmlunit 1
org.custommonkey.xmlunit.Diff diff1 = new org.custommonkey.xmlunit.Diff(xml1, xml2);
diff1.overrideElementQualifier(new RecursiveElementNameAndTextQualifier());
System.out.println("diff1.similar(): " + diff1.similar());
// xmlunit 2
org.xmlunit.diff.Diff diff2 = DiffBuilder
.compare(Input.fromString(xml1))
.withTest(Input.fromString(xml2))
.checkForSimilar()
.withNodeMatcher(new DefaultNodeMatcher(new ByNameAndTextRecSelector()))
.build();
System.out.println("diff2.hasDifferences(): " + diff2.hasDifferences());
diff2.getDifferences().forEach(difference -> System.out.println(difference));
}
}
I'm trying to do matching where the element order of elements with different names may vary. In xmlunit 1 I used
RecursiveElementNameAndTextQualifier, perhaps wrongly. In xmlunit 2, I thought the user guide is saying thatByNameAndTextRecSelectorshould work analogously, but I'm not successful. Here's a short test. Am I reading the user guide wrong, or perhaps it could use a clarification?