[jdom-interest] Schema validating... during WRITING

Laurent Bihanic laurent.bihanic at atosorigin.com
Tue Oct 30 15:21:44 PDT 2007


Hi,

Jorge Pacheco a écrit :
> Need to tell before going on that I'm not an jdom expert.
> 
> I know how to validate an existing XML against a schema while reading,
> parsing; I use SAXBuilder and tell it to do it.
> 
> Now I need to do the other direction; I create on the fly an XML and I
> want to validate the creation as well as the parsing.
> How can I do it? Should I just create it and right afterwards read it
> and validate it with SAXBuilder too?
> Should I use SAXOutputter?

Yes, you could that but the jdom-contrib projet already includes a wrapper for 
SAXOutputter that performs schema validation using Sun's multi-schema 
validator: org.jdom.contrib.schema.Schema.

The javadoc explains it all but validating a document sums up to:
     Schema schema = Schema.parse(uri, Schema.W3C_XML_SCHEMA);
     List errors = schema.validate(doc);

Regards,

Laurent



More information about the jdom-interest mailing list