英文:
XMLUnit throws NullPointerException when creating Diff object for valid xml
问题
我正在使用 org.custommonkey.xmlunit;(版本1.2)
。
在构建 Diff
对象时:
Diff diff = new Diff(expected, generated);
我总是遇到空指针异常,因为它在 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,但都没有起作用。
英文:
I am using org.custommonkey.xmlunit; (version 1.2)
.
While building Diff
object:
Diff diff = new Diff(expected, generated);
I always have NullPointerException as it's failing on this.controlDoc = this.getManipulatedDocument(controlDoc);
.
While debugging I found that in first constructor:
public Diff(String control, String test) throws SAXException, IOException {
this((Reader)(new StringReader(control)), (Reader)(new StringReader(test)));
}
there are proper xmls however when:
public Diff(Reader control, Reader test) throws SAXException, IOException {
this(XMLUnit.buildDocument(XMLUnit.newControlParser(), control), XMLUnit.buildDocument(XMLUnit.newTestParser(), test));
}
is called I see in debugger [#document: null]
. Why is that so? I tried with many xmls, even really easy and small which I found in internet but nothing works.
答案1
得分: 0
Oh, 我刚刚发现 XMLUnit.setIgnoreWhitespace(true);
引起了这个问题,因为在项目中我正在使用古老版本的 Saxon 库,而在版本 8.9 中已经修复了这个问题。然而这个:
XMLUnit.setTransformerFactory("org.apache.xalan.processor.TransformerFactoryImpl");
非常有帮助。
英文:
Oh, I just have found that XMLUnit.setIgnoreWhitespace(true);
cause this problem because in project I am using Saxon library in ancient version and it was fixed in version 8.9 however this:
XMLUnit.setTransformerFactory("org.apache.xalan.processor.TransformerFactoryImpl");
helps a lot.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论