[jdom-interest] Newbie: Schema validation of a document being built via JDOM

Jason Hunter jhunter at collab.net
Fri Mar 23 17:31:31 PST 2001


Kevin Baynes wrote:
> 
> I got interested in this question and just wanted to toss some ideas out to
> the group:
> 
> If there were a Document.validate(), should it return a JDOMException? or a
> boolean?

A boolean is definitely wrong, because you need to know something about
the error.  An Exception is a good way to go.  Throw
InvalidDocumentException perhaps.  A possible alternate is to use an
ErrorHandler interface if there may be errors encountered that aren't
fatal.  I can't think of any right now though, so IDEx seems best.  The
method can return void.

> For a document to validate itself, couldn't it use this.getSerializedForm()
> to get its own data, put it into a SAXBuilder and catch any
> JDOMExceptions?(once getSerializedForm is implemented, that is)
> 
> Also, the document wouldn't know which parser built it. So in order to have
> the document validate against the right parser the validate method might
> have to look like:
> 
> public JDOMException validate(java.lang.String saxDriverClass) {}

It's true we could implement a validate() method right away using a
parser as the back-end.  I think I'd rather hold off until we really do
in-memory scans though.  Just a gut instinct thing.

-jh-



More information about the jdom-interest mailing list