比較する XML が 2 つあります。
File1.xml
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<member>
<SchoolID>1021</SchoolID>
<CandidateType>First Year</CandidateType>
<CandidateName>John</CandidateName>
</member>
File2.xml
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<member>
<CandidateID>3147</CandidateID>
<SchoolID>1021</SchoolID>
<CandidateType>Second Year</CandidateType>
<CandidateName>Peter</CandidateName>
</member>
xmlunit を使用して比較していますが、得られる出力は次のようになります。
Similar? false
Identical? false
***********************
Expected number of child nodes '2' but was '3' - comparing <member...> at /member[1] to <member...> at /member[1]
***********************
***********************
Expected sequence of child nodes '0' but was '1' - comparing <SchoolID...> at /member[1]/SchoolID[1] to <SchoolID...> at /member[1]/SchoolID[1]
***********************
***********************
Expected text value 'John' but was 'Peter' - comparing <CandidateName ...>John</CandidateName> at /member[1]/CandidateName[1]/text()[1] to <CandidateName ...>Peter</CandidateName> at /member[1]/CandidateName[1]/text()[1]
***********************
***********************
Expected sequence of child nodes '1' but was '2' - comparing <CandidateName...> at /member[1]/CandidateName[1] to <CandidateName...> at /member[1]/CandidateName[1]
***********************
***********************
Expected presence of child node 'null' but was 'CandidateID' - comparing at null to <CandidateID...> at /member[1]/CandidateID[1]
次の違いのみがわかるように出力を表す必要があります。File1.xml に Node CandidateID がなく、Node CandidateName のデータが異なります。余分な詳細は必要ありません。detDiff.getAllDifferences() の出力を微調整する方法はありますか。
コードのスナップショットは次のようになります。
try {
// fr1 and fr2 are my two xml files.
Diff diff = new Diff(fr1, fr2);
System.out.println("Similar? " + diff.similar());
System.out.println("Identical? " + diff.identical());
DetailedDiff detDiff = new DetailedDiff(diff);
List differences = detDiff.getAllDifferences();
for (Object object : differences) {
Difference difference = (Difference)object;
System.out.println("***********************");
System.out.println(difference);
System.out.println("***********************");
}