DocumentBuilderFactory configuration is being ignored #86

Closed
fadc80 opened this Issue Jun 18, 2016 · 2 comments

Projects

None yet

2 participants

@fadc80
fadc80 commented Jun 18, 2016

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?

@bodewig bodewig added bug core labels Jun 19, 2016
@bodewig bodewig added this to the 2.2.1 milestone Jun 19, 2016
@bodewig
Member
bodewig commented Jun 19, 2016

I've published a snapshot of 2.2.1 that should fix it but need to look deeper into the case of ignoreComments as it uses XSLT under the covers.

@bodewig bodewig closed this in b258236 Jun 19, 2016
@bodewig
Member
bodewig commented Jun 19, 2016

I've published 2.2.1, it should be available from Maven Central soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment