Сравниваем два простых XML и хотим сравнить узлы с конкретным localName.В этом случае только flowerA
.Когда я использую не равно flowerB
, это дает мне разницу для узла flowerA
, когда я говорю, равно flowerA
, это не дает никакой разницы?
public class XMLDiff {
public static void main(String[] args) {
String controlXml = "<flowers><flowerA>Rose</flowerA><flowerB>Daisy</flowerB></flowers>";
String testXml = "<flowers><flowerA>Roses</flowerA><flowerB>Daisies</flowerB></flowers>";
Diff build = DiffBuilder.compare(controlXml).withTest(testXml)
.ignoreWhitespace()
.withNodeFilter(node -> !node.getNodeName().equals("flowerB"))
.build();
System.out.println(build.getDifferences());
}
}
[Expected text value 'Rose' but was 'Roses' - comparing <flowerA ...>Rose</flowerA> at /flowers[1]/flowerA[1]/text()[1] to <flowerA ...>Roses</flowerA> at /flowers[1]/flowerA[1]/text()[1] (DIFFERENT)]
public class XMLDiff {
public static void main(String[] args) {
String controlXml = "<flowers><flowerA>Rose</flowerA><flowerB>Daisy</flowerB></flowers>";
String testXml = "<flowers><flowerA>Roses</flowerA><flowerB>Daisies</flowerB></flowers>";
Diff build = DiffBuilder.compare(controlXml).withTest(testXml)
.ignoreWhitespace()
.withNodeFilter(node -> node.getNodeName().equals("flowerA"))
.build();
System.out.println(build.getDifferences());
}
}
[]