[jdom-interest] SAXBuilder / JAXP error

Dennis Sosnoski dms at sosnoski.com
Mon Nov 5 01:34:44 PST 2001


If this is the cause using a subclass of SAXBuilder may be a cleaner 
solution. I had to do this in order to get JDOM to work with the Crimson 
parser in a Tomcat environment. The problem in my case was that the SAX 
XMLReaderFactory code goes through some convoluted logic to find the 
correct classpath when you pass it a classname String, and it refused to 
recognize Crimson no matter what I tried. Everything seems to work fine 
now when I bypass the JAXP usage and go direct in a SAXBuilder subclass:

   private static class CrimsonBuilder extends SAXBuilder
    {
        public CrimsonBuilder(boolean validate) {
            super(validate);
        }
       
        protected XMLReader createParser() throws Exception {
            return new org.apache.crimson.parser.XMLReaderImpl();
        }
    }

The same approach should work fine in other cases if you know the parser 
class you want to use.

  - Dennis

Laurent Bihanic wrote:

>
> Jason Hunter wrote:
>
>> I wonder if Weblogic 6.1 reimplemented the JAXP libraries and added this
>> as a bug.
>>
>
> This is actually a known problem in SAXBuilder: On the first call to 
> createParser (via build), SAXBuilder caches the class name of the SAX 
> parser, even when JAXP was used to create the parser instance:
> 462              saxDriverClass = parser.getClass().getName();
>
> If you try to reuse a SAXBuilder instance, it will not longer use JAXP 
> to create the parser but will use:
>         if (saxDriverClass != null) {
>             // The user knows that they want to use a particular class
>             parser = XMLReaderFactory.createXMLReader(saxDriverClass);
>             // System.out.println("using specific " + saxDriverClass);
>         } else {
>
> In this case, BEA are not wrong: they just have no no-args public 
> contructor for their parser, which makes it inedible by XMLReaderFactory.
>
> This issue has already been discussed on this list but no changes were 
> made to SAXBuilder (but I don't remember why!). So, my fix is just to 
> comment out the line "saxDriverClass = ..." in the JAXP part of 
> createParser every time I get a new JDOM version.
>
> Hope this helps,
>
> Laurent






More information about the jdom-interest mailing list