2 つの XML があります
<books><book language="English"><authors><author>Niklaus Wirth</author></authors></book><book language="English"><authors><author>Mark Twain</author></authors></book><book language="English"><authors><author>O.-J. Dahl</author></authors></book></books>
<books><book language="English"><authors><author>Niklaus Wirth</author></authors></book><book language="English"><authors><author>O.-J. Dahl</author></authors></book><book language="English"><authors><author>Mark Twain</author></authors></book></books>
最後の 2 つの<author>
タグの順序は異なりますが、似ているはずです。これがコードです
public static void compare() throws FileNotFoundException{
String sourceXML=convertXMLtoString(source);
String targetXML=convertXMLtoString(target);
System.out.println(sourceXML);
System.out.println(targetXML);
Diff mydiff=DiffBuilder.compare(sourceXML)
.withTest(targetXML)
.withNodeMatcher(new DefaultNodeMatcher(ElementSelectors.byNameAndText))
.checkForSimilar()
//.withNodeMatcher()
.build();
Iterable<Difference> differences = mydiff.getDifferences();
for(Difference d:differences){
System.out.println(d.toString());
}
}
これが出力です。
Expected child 'author' but was 'null' - comparing <author...> at /books[1]/book[2]/authors[1]/author[1] to <NULL> (DIFFERENT)
Expected child 'null' but was 'author' - comparing <NULL> to <author...> at /books[1]/book[2]/authors[1]/author[1] (DIFFERENT)
Expected child 'author' but was 'null' - comparing <author...> at /books[1]/book[3]/authors[1]/author[1] to <NULL> (DIFFERENT)
Expected child 'null' but was 'author' - comparing <NULL> to <author...> at /books[1]/book[3]/authors[1]/author[1] (DIFFERENT)
これを無視する方法を誰か教えてもらえますか? NameandText を要素セレクターで使用すると、順序を無視する必要があると思いました。ありがとう