[jdom-interest] Using XSD schema to validate a JDOM tree

Olivier Coppel olivier.coppel at akazi.com
Tue Sep 17 05:37:42 PDT 2002


I succeed in validating JDOM tree with an XSD schema by  :
1) using method  "setValidation( true )" of org.jdom.input.SAXBuilder class
2) adding "xsi:schemaLocation="myNamespace myXSDSchemaFile" attribute in
every file I want to validate
It works very well. I've tried it sucessfully.

The problem is that I don't want to add "xsi:schemaLocation" attribute in
every XML file.
I've read that there is a way to specify the name of the XSD schema directly
in my program by using parser properties :
1) propertie "http://java.sun.com/xml/jaxp/properties/schemaLanguage" with
value "http://www.w3.org/2001/XMLSchema"
2) propertie "http://java.sun.com/xml/jaxp/properties/schemaSource" with
value "File(myXSDSchemaFile)"

First, I have to overload the protected method "configureParser(XMLReader
parser, SAXHandler contentHandler)" of SAXBuilder by doing :

  protected void configureParser(XMLReader parser, SAXHandler
                  throws Exception {
    super.configureParser( parser, contentHandler );
    try {

"http://java.sun.com/xml/jaxp/properties/schemaSource", new
File("myXSDSchemaFile") );
    catch (SAXNotRecognizedException x) {

But it doesn't work. It seems that only validation by DTD works but not with
XSD schema.

I used:
. JDK 1.3.1
. JDOM Beta 7
. the parser is default parser Xerces 1.4.4
. Jaxp 1.1

I tried with Xerces 2.1, Jaxp 1.2 but the result is the same ... it doesn't

Is there a way to solve this problem ?


Olivier Coppel

More information about the jdom-interest mailing list