[jdom-interest] Getting schema validation working without enabling Xerces namespace support. How?

Travers Waker traversw at innoforge.co.za
Wed Sep 13 04:37:29 PDT 2000

Hi everyone.

Lets finally settle this thread.

This is an extract from the September archives of the jdom-interest mailing

>> I also struggled with namespaces and I found that in SAXBuilder
>> the fact
>> that the "namespaces" feature is hardwired to false prevents
>> correct handling of schemas. Setting the property to true seemed to
>> solve
>> the problem.
>> This is an issue that I brought to the list but no one answered.
>> Why is this property hardwired to false ?

>Because JDOM does its own namespace handling, which allows namespaces
>and validation to work at the same time.


I might be wrong, but I get the impression that Jason's reply implies that
schema validation still works when Xerces namespace handling is disabled
because JDOM does its own namespace handling.  However, this is definitely
not my experience (the schema is ignored when Xerces namespace handling is
disabled) .  So, how does one get schema validation working without enabling
Xerces namespace handling?

In particular, how do I get the very simple example code in the email
attached below to work without first enabling Xerces namespace handling?

------------- Email sent to Scott Ellsworth on 12 September ---------------

Hi Scott.

I've got the Schemas working with JDOM.  The main problem was that JDOM
defaults to disabling namespace support in Xerces, which breaks schema
support.  You just have to go into the source file
jdom/src/java/org/jdom/input/SAXBuilder.java and edit the line that looks
like this:

  parser.setFeature("http://xml.org/sax/features/namespaces", false);

and change it to:

  parser.setFeature("http://xml.org/sax/features/namespaces", true);

Then rerun JDOM's Build script to get Ant to include your change into the
new jdom.jar, and copy the jdom.jar to wherever you keep your jar libraries.

After that, the following simple example works fine, throwing an exception
because validation by the schema fails.

File: test.xml
<?xml version="1.0" encoding="UTF-8"?>

<tag xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance"

File: test.xsd
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/1999/XMLSchema">

<xsd:simpleType name="LimitedInt" base="xsd:integer">
  <xsd:minInclusive value="2"/>

<xsd:element name="tag" type="LimitedInt"/>


File: JdomTest.java
package tests.jdom;
import java.io.File;
import org.jdom.*;
import org.jdom.input.*;

class JdomTest {

  public static void main(String[] args) throws Exception {

    SAXBuilder builder = new SAXBuilder(true);
    Document doc = builder.build(new File("VagasConfig.xml

    Element currentElement = doc.getRootElement();
    String content = currentElement.getContent();

    System.out.println("The <tag> field contains: " + content);

More information about the jdom-interest mailing list