[jdom-interest] In-memory validation against schemas

Laurent Bihanic laurent.bihanic at atosorigin.com
Mon Apr 28 06:03:24 PDT 2003


Hi,

Attached is a proposal for supporting in-memory validation of JDOM documents 
against schemas.
This code relies on JARV (Java API for RELAX Verifiers, 
http://iso-relax.sourceforge.net/JARV/) and Sun's Multi-Schema Validator 
implementation.

To validate a document against a W3C XML Schema definition:

import org.jdom.contrib.schema.Schema;

       String uri = <The URL of the schema document>;
       Document doc = <a JDOM document>;

       Schema schema = Schema.parse(uri, Schema.W3C_XML_SCHEMA);
       List errors = schema.validate(doc);
       if (errors != null) {
          // Validation errors
          for (Iterator i=errors.iterator(); i.hasNext(); ) {
             ValidationError e = (ValidationError)(i.next());

             System.out.println(e);
          }
       }
       // Else: No error, document is valid.

The current limitations are those of JARV, i.e. no support for validating a 
document against multiple schemas. This can be work around for elements 
(calling validate(Element) on another Schema) but not for attributes.

Regards,

Laurent

-------------- next part --------------
A non-text attachment was scrubbed...
Name: Schema.java
Type: text/x-java
Size: 19526 bytes
Desc: not available
Url : http://jdom.org/pipermail/jdom-interest/attachments/20030428/975508e6/Schema.bin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ValidationError.java
Type: text/x-java
Size: 6987 bytes
Desc: not available
Url : http://jdom.org/pipermail/jdom-interest/attachments/20030428/975508e6/ValidationError.bin


More information about the jdom-interest mailing list