[jdom-interest] Problems with Xerces 2.0.0

Martin Berens mhb at biss-net.com
Thu Jan 31 04:29:49 PST 2002


Hello everyone,

I tried a current JDOM snapshot (from yesterday ;)) with
Xerces 2.0.0 and wanted to do a bit XML schema validation
and got the following results ("system.xml" is an XML file
with a "system.xsd" schema definition file in the same
directory - worked fine with JDOM beta 7 and an older
1.x release of Xerces).

My Test program:

import org.jdom.input.SAXBuilder;
import org.jdom.Document;
import java.io.File;

public class SimpleTest {
   public static void main ( String[] straArgs ) {
     try {
       SAXBuilder builder = new SAXBuilder();
       // (= 1 =)
       builder.setValidation( true );
       // (= 2 =)
       builder.setFeature(
         "http://xml.org/sax/features/validation", true );
       // (= 3 =)
       builder.setFeature(
         "http://xml.org/sax/features/validation/schema", true );

       Document doc = builder.build( new File( "c:/system.xml" ) );
     }
     catch ( Exception e ) {
       e.printStackTrace();
     }
   }
}

(= 1 =):
Having only line (= 1 =) I get the following exception
(seems that only DTD validation is set true?):

org.jdom.JDOMException: Error on line 3 of document file:/c:/system.xml: 
Documen
t root element "system", must match DOCTYPE root "null".
         at org.jdom.input.SAXBuilder.build(SAXBuilder.java:363)
         at org.jdom.input.SAXBuilder.build(SAXBuilder.java:707)
         at org.jdom.input.SAXBuilder.build(SAXBuilder.java:689)
         at SimpleTest.main(SimpleTest.java:12)
Caused by: org.xml.sax.SAXParseException: Document root element 
"system", must m
atch DOCTYPE root "null".
         at org.apache.xerces.parsers.AbstractSAXParser.parse(Unknown 
Source)
         at org.jdom.input.SAXBuilder.build(SAXBuilder.java:354)
         at org.jdom.input.SAXBuilder.build(SAXBuilder.java:707)
         at org.jdom.input.SAXBuilder.build(SAXBuilder.java:689)
         at SimpleTest.main(SimpleTest.java:12)

(= 2 =):
Having only line (= 2 =) I get no exception, but schema validation
does not occur (changed the XML file in a way it cannot validate).

(= 3 =):
Having only line (=3 =) I get the following exception:

org.jdom.JDOMException: http://xml.org/sax/features/validation/schema 
feature no
t recognized for SAX driver null
         at 
org.jdom.input.SAXBuilder.internalSetFeature(SAXBuilder.java:638)
         at org.jdom.input.SAXBuilder.configureParser(SAXBuilder.java:526)
         at org.jdom.input.SAXBuilder.build(SAXBuilder.java:351)
         at org.jdom.input.SAXBuilder.build(SAXBuilder.java:707)
         at org.jdom.input.SAXBuilder.build(SAXBuilder.java:689)
         at SimpleTest.main(SimpleTest.java:12)

Any hints what happens here? Xerces 2 seems to become the default
XML parser for JDK 1.4. Therefore this should work ;).

Greetings,

Martin




More information about the jdom-interest mailing list