I'm using XMLUnit to do unit testing of XML output files. (Charles, thanks very much for the suggestion!) I've got it working pretty well, and the documentation is pretty good.
However, I have one problem that I can't find the answer to. I posted a question on the XMLUnit SourceForge forum a few days ago and haven't gotten any responses. (That forum is not very active.) So I thought I'd try here.
I am using Eclipse and have a small test project and my live project, build my Maven, that incorporates lots of third-party libraries. On my test project, I can set XMLUnit.setIgnoreWhitespace(true) and it works as advertised.
However, on my live project, I get a NullPointerException when I try to use this option. It works ok if this is set to false. Here is a partial stack trace of the NPE:
ava.lang.NullPointerException at net.sf.saxon.Controller.prepareInputTree(Controller.java:1386) at net.sf.saxon.Controller.transform(Controller.java:1318) at org.custommonkey.xmlunit.Transform.transformTo(Transform.java:211) at org.custommonkey.xmlunit.Transform.getResultDocument(Transform.java:233) at org.custommonkey.xmlunit.Diff.getWhitespaceManipulatedDocument(Diff.java:187) at org.custommonkey.xmlunit.Diff.getManipulatedDocument(Diff.java:209) at org.custommonkey.xmlunit.Diff.<init>(Diff.java:154) at org.custommonkey.xmlunit.Diff.<init>(Diff.java:144) at org.custommonkey.xmlunit.Diff.<init>(Diff.java:108) at org.custommonkey.xmlunit.Diff.<init>(Diff.java:100) at org.custommonkey.xmlunit.Diff.<init>(Diff.java:92) etc.
One difference in the two projects is that they are using different control parsers. If I do
but I think I've got the syntax wrong. This gives me the error:
avax.xml.parsers.FactoryConfigurationError: Provider com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl could not be instantiated: java.lang.InstantiationException: com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl at javax.xml.parsers.DocumentBuilderFactory.newInstance(DocumentBuilderFactory.java:104) at org.custommonkey.xmlunit.XMLUnit.getControlDocumentBuilderFactory(XMLUnit.java:181) at org.custommonkey.xmlunit.XMLUnit.setControlParser(XMLUnit.java:128) etc.
Any ideas on how to fix this -- or perhaps where else to ask -- will be greatly appreciated. Thanks!
Lasse, thank you very much for the tip. I resolved the issue as follows:
1. I discovered through trial and error that the problem arose because the live project had "saxon-8.7.jar" in the build path. When I added this to the test project, I got the same failure. 2. In the XMLUnit documentation, there is an example command to change the transformer factory used by XMLUnit as follows: