Reputation: 5799
I have 2 XML files and when comparing them using XMLUNIT, I get the below exception.
Exception in thread "main" org.w3c.dom.DOMException: NAMESPACE_ERR: An attempt is made to create or change an object in a way which is incorrect with regard to namespaces.
at com.sun.org.apache.xerces.internal.dom.CoreDocumentImpl.checkDOMNSErr(CoreDocumentImpl.java:2530)
at com.sun.org.apache.xerces.internal.dom.AttrNSImpl.setName(AttrNSImpl.java:117)
at com.sun.org.apache.xerces.internal.dom.AttrNSImpl.<init>(AttrNSImpl.java:78)
at com.sun.org.apache.xerces.internal.dom.CoreDocumentImpl.createAttributeNS(CoreDocumentImpl.java:2142)
at com.sun.org.apache.xerces.internal.dom.CoreDocumentImpl.importNode(CoreDocumentImpl.java:1596)
at com.sun.org.apache.xerces.internal.dom.CoreDocumentImpl.importNode(CoreDocumentImpl.java:1560)
at com.sun.org.apache.xerces.internal.dom.CoreDocumentImpl.cloneNode(CoreDocumentImpl.java:362)
at com.sun.org.apache.xerces.internal.dom.DocumentImpl.cloneNode(DocumentImpl.java:159)
at org.custommonkey.xmlunit.XMLUnit.stripWhiteSpaceWithoutXSLT(XMLUnit.java:522)
at org.custommonkey.xmlunit.XMLUnit.getWhitespaceStrippedDocument(XMLUnit.java:506)
at org.custommonkey.xmlunit.Diff.getWhitespaceManipulatedDocument(Diff.java:182)
at org.custommonkey.xmlunit.Diff.getManipulatedDocument(Diff.java:203)
at org.custommonkey.xmlunit.Diff.<init>(Diff.java:155)
at org.custommonkey.xmlunit.Diff.<init>(Diff.java:168)
at org.custommonkey.xmlunit.DetailedDiff.<init>(DetailedDiff.java:60)
I am using the below code and it does not work as expected.
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setValidating(false);
try {
factory.setFeature("http://xml.org/sax/features/namespaces", false);
factory.setFeature("http://xml.org/sax/features/validation", false);
factory.setFeature("http://apache.org/xml/features/nonvalidating/load-dtd-grammar", false);
factory.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);;
} catch (ParserConfigurationException e) {
e.printStackTrace();
}
XMLUnit.setTestDocumentBuilderFactory(factory);
XMLUnit.setControlDocumentBuilderFactory(factory);
XMLUnit.setIgnoreWhitespace(Boolean.TRUE);
XMLUnit.setIgnoreComments(true);
XMLUnit.setIgnoreAttributeOrder(true);
How can I make XMLUNIT ignore namespace validations?
Upvotes: 0
Views: 549
Reputation: 5799
Removing the 2 below lines made my code work as expecting.
factory.setFeature("http://xml.org/sax/features/namespaces", false);
factory.setFeature("http://xml.org/sax/features/validation", false);
Upvotes: 0