您好我正在尝试使用 xmlunit 比较两个 xml 文件的内容
这是我的输入 xmls
参考.xml
<?xml version="1.0" encoding="UTF-8"?>
<books>
<book>
<name>abc</name>
<isbn>9971-5-0210-0</isbn>
<author>abc</author>
<category></category>
</book>
<book>
<name>def</name>
<isbn>9971-5-0222-0</isbn>
<author>def</author>
</book>
</books>
比较.xml
<?xml version="1.0" encoding="UTF-8"?>
<books>
<book>
<name>abc</name>
<isbn>9971-5-0210-0</isbn>
<author>abc</author>
<category></category>
</book>
<book>
<name>def</name>
<isbn>9971-5-0222-0</isbn>
<author>def</author>
</book>
<book>
<name>ghi</name>
<isbn>9971-5-0222-0</isbn>
<author>test authora</author>
</book>
</books>
在这里我们可以观察到compare.xml
有 3 个 book 节点。
我正在打印总差异并计算如下
DetailedDiff detDiff = new DetailedDiff(diff);
List differences = detDiff.getAllDifferences();
System.out.println("Total differences:-->"+differences.size());
for (Object object : differences) {
Difference difference = (Difference)object;
System.out.println("***********************");
System.out.println(difference);
System.out.println("***********************");
}
输出:
**Total differences:-->4
子节点的预期数量为“5”,但为“7” - 在 /books[1] 与 /books[1] 进行比较
预期文本值 ' ' 但为 ' ' - 在 /books[1]/text()[3] 与 /books[1]/text()[3] 进行比较
预期存在子节点“null”但为“book” - 在 null 与 /books[1]/book[3] 进行比较
子节点“null”的预期存在但为“#text” - 在 null 与 /books[1]/text()[4] 进行比较
相反,有什么办法可以让我将更改视为只有 1(因为我认为只添加了一个书节点,而忽略了内部标签),并且还可以将输出自定义为我们的自定义消息