Title: JAXP via reflection????

In the documentation of org.dom4j.io.SAXReader class, following is written:

" If the org.xml.sax.driver system property is not defined then JAXP is used via reflection (so that DOM4J is not explicitly dependent on the JAXP classes) to load the JAXP configured SAXParser. "

I haven't understood the meaning of above sentence.

When I run the following code, I get the warning "Warning: Error occurred using JAXP to load a SAXParser. Will use Aelfred instead."

public static void main(String argv[]) {
        try {

            URL fileURL = new File("anyfile.xml").toURL();

            SAXReader reader = new SAXReader();
            Document doc = reader.read(fileURL);

            System.out.print(doc.asXML()) ;

        } catch (Exception e) {
           e.printStackTrace(System.err);
          }
}

Can anyone tell me how to avoid Aelfred and load JAXP onfigured SAXParser instead?

Please note that I  don't get any warning or error if I use org.xml.sax.driver system property as in following code:

public static void main(String argv[]) {
        try {

            URL fileURL = new File("report.xml").toURL();

           System.setProperty("org.xml.sax.driver","org.apache.xerces.parsers.SAXParser");
          
           XMLReader xr = XMLReaderFactory.createXMLReader() ;

           SAXReader reader = new SAXReader(xr);

           Document doc = reader.read(fileURL);

           System.out.print(doc.asXML()) ;

        } catch (Exception e) {
            e.printStackTrace(System.err);
            }
}

 

Reply via email to