我正在使用以下帖子中的示例代码(可能重复)来比较我的XML文件acdcjunior - Best way to compare 2 XML documents in Java
我从断言测试中看到以下错误。
Expected presence of doctype declaration 'null' but was 'not null' - comparing at to <!DOCTYPE plist PSECTOR " ..........
有人可以指导我做些什么来解决这个问题吗?
答案 0 :(得分:0)
好的,我在这里找到了解决方案 - http://xmlunit.sourceforge.net/userguide/XMLUnit-Java.pdf
出于效率原因,只要找到第一个差异,Diff就会停止比较过程。获得所有的差异 在两个XML之间,需要一个DetailedDiff类的实例,一个Diff的子类。注意一个详细 Diff使用现有的Diff实例构建。
对于未来的读者,这里是解决方案(也在链接 - 第9页) -
DifferenceListener myDifferenceListener = new IgnoreTextAndAttributeValuesDifferenceListener();
Diff myDiff = new Diff(expectedXML, actualXML);
myDiff.overrideDifferenceListener(myDifferenceListener);
Assert.assertTrue("test XML matches control skeleton XML", myDiff.similar());
再次从链接
The DifferenceEngine class generates the events that are passed to a DifferenceListener implementation as two
pieces of XML are compared. Using recursion it navigates through the nodes in the control XML DOM, and determines which
node in the test XML DOM qualifies for comparison to the current control node. The qualifying test node will match the control
node’s node type, as well as the node name and namespace (if defined for the control node).