[jdom-interest] Re: XML Schema Validation
Larry_Davies at notes.compaid.com
Wed May 9 05:15:24 PDT 2001
To answer the questions some are having regarding using schemas, the answer is
Yes/No. As others have mentioned, JDOM does not in and of itself validate
schemas. The underlying parser (like Xerces) validates the xml document against
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 Xerces
version 1.3.0. FYI, the older version of Xerces 1.2.0 does not work for schema
validation. To validate the document using JDOM, I believe you must instantiate
the builder as follows: SAXBuilder builder = new SAXBuilder(true). In addition,
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"?>
The localhost reference could be your domain name and the mySchema.xsd is the
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 it
did not work for me until I did that.
Anyway, there may be other ways, but this worked fine for me.
More information about the jdom-interest