I am trying to compare two XHTML documents using XMLUnit 2.2.0. However, it is taking too long. I guess the library is downloading DTD files from Internet.
I thought I could disable DTD validation setting a document builder factory using the method DiffBuilder.withDocumentBuilderFactory().
I am using the following test code:
public class Test {
public static void main(String args[]) throws ParserConfigurationException {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setValidating(false);
dbf.setFeature("http://xml.org/sax/features/validation", false);
dbf.setFeature("http://apache.org/xml/features/nonvalidating/load-dtd-grammar", false);
dbf.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
Diff d = DiffBuilder.compare(
Input.fromString(
"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \n"
+" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n"
+"<html xmlns=\"http://www.w3.org/1999/xhtml\">\n"
+" <head></head>\n"
+" <body>some content 1</body>\n"
+"</html>")).withTest(
Input.fromString(
"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \n"
+" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n"
+"<html xmlns=\"http://www.w3.org/1999/xhtml\">\n"
+" <head></head>\n"
+" <body>some content 2</body>\n"
+"</html>")).withDocumentBuilderFactory(dbf).ignoreWhitespace().build();
if(d.hasDifferences())
for (Difference dd: d.getDifferences()) {
System.out.println(dd.toString());
}
}
}
It did not work. My code runs fast just when I remove the DOCTYPE definition from the XHTML snippets.
I have posted this issue to SO too How to disable XMLUnit DTD validation?
I am trying to compare two XHTML documents using XMLUnit 2.2.0. However, it is taking too long. I guess the library is downloading DTD files from Internet.
I thought I could disable DTD validation setting a document builder factory using the method
DiffBuilder.withDocumentBuilderFactory().I am using the following test code:
It did not work. My code runs fast just when I remove the DOCTYPE definition from the XHTML snippets.
I have posted this issue to SO too How to disable XMLUnit DTD validation?