[jdom-interest] Re: XML Schema Validation

Kenworthy, Edward edward.kenworthy at exchange.co.uk
Wed May 9 05:49:03 PDT 2001

Hi Larry

Ah ! 	That's interesting, thanks. What happens if the XML document doesn't
conform to the schema ? Does the builder give up or do you end up with a
Document that is flagged as non-conforming that you can still work with ? (I
would prefer the latter as in my app whilst documents do have schemas it is
valid for them to be non-conforming as in incomplete (eg Element foo should
have child bar, but it doesn't yet) but not for them to be invalid (eg
Element foo cannot have a child wibble.) Uhm, hope that made sense.


-----Original Message-----
From: Larry Davies [mailto:Larry_Davies at notes.compaid.com]
Sent: 09 May 2001 13:15
To: jdom-interest at jdom.org
Subject: [jdom-interest] Re: XML Schema Validation

To answer the questions some are having regarding using schemas, the answer
Yes/No.  As others have mentioned, JDOM does not in and of itself validate
schemas.  The underlying parser (like Xerces) validates the xml document
a schema.  I recently had some problems getting my XML document to parse and
validate against a schema using JDOM Beta 6.  I got it to work now.  You
have to
be using a version of a parser that will validate with schemas.  I used
version 1.3.0.  FYI, the older version of Xerces 1.2.0 does not work for
validation.  To validate the document using JDOM, I believe you must
the builder as follows: SAXBuilder builder = new SAXBuilder(true).  In
you must have your XML document point to your schema.  The following is a
snippet from my XML document and Schema document.

<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2000/10/XMLSchema"

XML document:
<Data xmlns="http://localhost"
      xsi:schemaLocation="http://localhost mySchema.xsd">

The localhost reference could be your domain name and the mySchema.xsd is
name for your schema document.  I believe you may also need to tell JDOM
to use the namespace http://localhost.  Not 100% sure on that, but I believe
did not work for me until I did that.

Anyway, there may be other ways, but this worked fine for me.


To control your jdom-interest membership:

More information about the jdom-interest mailing list