[jdom-interest] Validation using schemas, how?

Travers Waker traversw at innoforge.co.za
Fri Sep 8 04:27:03 PDT 2000

Hi Jdom mailing list subscribers.

I'm struggling with validating with schemas using JDOM.  I'm  trying to get
a simple-as-can be schema to validate a simple-as-can-be XML doc.  I've
included what I think should work

I'm expecting this minimal test program to throw an exception because the
contents of <tag> is 1, and I thought I was constraining it to being an
integer >= 2 in test.xsd.  It doesn't behave like I expected (no Exception
is thrown).  Also, when I call "new SAXBuilder(true)" with my code like it
is, I get a message saying I must define the <tag> element.  specifying a
dtd sorts that out, but surely one doesn't have to use both a dtd and a
schema for validation - a schema on its own should be acceptable too.

BTW, the latest complete download of Jdom in the CVS repository does not
seem to be complete.  The jdom-complete.zip I downloaded wouldn't build
becasue it didn't have Ant and Xerces in the lib directory.

I feel a bit bad about this post because it's more a newbie request for help
than a contribution towards the coding of Jdom.  Maybe it's time for a
jdom-help mailing list.

Thanks to anyone who can help.


File: test.xml

  <!DOCTYPE tag>

File: test.xsd

  <schema xmlns="http://www.w3.org/1999/XMLSchema">

  <dataType name="limitedInt">
    <basetype name="integer"/>

  <elementType name="tag">
    <datatypeRef name="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();  // SHOULD THIS HAVE "true" ARG
    Document doc = builder.build(new File("test.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