我正在尝试比较以下两个 XML... 我正在做相似性测试。
XML1
<top>
<first>true</first> <!--- control node 1 ---->
<second> <!--- control node 2 ---->
<secondpart1>ooo</secondpart1>
</second>
<third> <!--- control node 3 ---->
<thirdpart1>zzzz</thirdpar1>
</third>
<third> <!--- control node 4 ---->
<thirdpart1>zzzz</thirdpar1>
<thirdpart2>zzzz</thirdpar2>
</third>
</top>
XML2
<top>
<second> <!--- test node 1 ---->
<secondpart1>ooo</secondpart1>
</second>
<third> <!--- test node 2 ---->
<thirdpart1>zzzz</thirdpar1>
</third>
<third> <!--- test node 3 ---->
<thirdpart1>zzzz</thirdpar1>
<thirdpart2>zzzz</thirdpar2>
</third>
<first>true</first> <!--- test node 4 ---->
</top>
我收到这个错误
[不同] 子节点的预期数量为“1”,但为“2”。看起来它将控制节点 3 与测试节点 3 进行比较。由于元素的名称与“第三”匹配,因此它进行了比较。有解决这种情况的方法吗?
这是我的代码
Diff d = new Diff(xmlResponseTrim, serializedResponseTrim);
DetailedDiff dd = new DetailedDiff(d);
dd.overrideDifferenceListener(new IgnoreTextAndAttributeValuesDifferenceListener());
System.out.println(dd);
assertTrue(dd.similar());