XMLUnit在为有效xml创建Diff对象时抛出NullPointerException



我正在使用org.custommonkey.xmlunit; (version 1.2)。构建Diff对象时:Diff diff = new Diff(expected, generated);

我总是有NullPointerException,因为它在this.controlDoc = this.getManipulatedDocument(controlDoc);上失败了。在调试时,我发现在第一个构造函数中:

public Diff(String control, String test) throws SAXException, IOException {
this((Reader)(new StringReader(control)), (Reader)(new StringReader(test)));
}

然而,当:时,有适当的xml

public Diff(Reader control, Reader test) throws SAXException, IOException {
this(XMLUnit.buildDocument(XMLUnit.newControlParser(), control), XMLUnit.buildDocument(XMLUnit.newTestParser(), test));
}

在调试器[#document: null]中被调用。为什么会这样?我尝试了许多xml,甚至是我在互联网上发现的非常简单和小的xml,但都不起作用。

哦,我刚刚发现XMLUnit.setIgnoreWhitespace(true);导致了这个问题,因为在项目中我使用的是古代版本的Saxon库,它在8.9版本中得到了修复,但是这个:

XMLUnit.setTransformerFactory("org.apache.xalan.processor.TransformerFactoryImpl");

帮助很大。

最新更新