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

Kevin Baynes kbaynes at renex.com
Fri Mar 23 09:32:12 PST 2001


> -----Original Message-----
> From: jdom-interest-admin at jdom.org
> [mailto:jdom-interest-admin at jdom.org]On Behalf Of Rick Nucci
> Sent: Wednesday, March 21, 2001 2:18 PM
> To: Kevin Baynes; jdom-interest at jdom.org
> Subject: RE: [jdom-interest] Newbie: Schema validation of a document
> being built via JDOM
>
>
> What if Document.validate() returns boolean, but also throws any
> validation
> exceptions?
>
> -Rick

I just thought that a boolean return would be a safe method that you didn't
have to wrap in a try {} catch() {} block. You would be able to do things
like:

if ( doc.validate() ) { // commit changes } else { // fail gracefully }

If it returned boolean and threw exceptions, you'd never get a boolean false
back, just an exception.

On another note, I've seen comments about keeping JDOM out of the validation
business and leaving that to the parsers. I think this is wise.

That's why I threw out the question of basically just rebuilding the
document through SAXBuilder and catching any JDOMExceptions. My vision was
really just a convenience method that prevented me from having to do
something like:

String xml = doc.getSerializedForm();
CharArrayReader car = new CharArrayReader( xml.toCharArray() );
SAXBuilder builder = new SAXBuilder( true );
boolean isValid;
try {
	builder.build( car );
	isValid = true;
} catch (JDOMException ex) {
	isValid = false;
}

if ( isValid ) { // commit changes } else { // fail gracefully }

-Kevin


>
> -----Original Message-----
> From: jdom-interest-admin at jdom.org
> [mailto:jdom-interest-admin at jdom.org]On Behalf Of Kevin Baynes
> Sent: Wednesday, March 21, 2001 2:51 PM
> To: Jason Hunter; Paul Jakubik
> Cc: jdom-interest
> Subject: RE: [jdom-interest] Newbie: Schema validation of a document
> being built via JDOM
>
>
> 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?
>
> Would the JDOMException contain enough information to be useful? Would you
> return null if the document was valid? Would you just want the boolean
> instead?
>
> 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) {}
>
> -Kevin
>
> -----Original Message-----
> From: jdom-interest-admin at jdom.org
> [mailto:jdom-interest-admin at jdom.org]On Behalf Of Jason Hunter
> Sent: Monday, March 19, 2001 12:01 PM
> To: Paul Jakubik
> Cc: jdom-interest
> Subject: Re: [jdom-interest] Newbie: Schema validation of a document
> being built via JDOM
>
>
> Paul Jakubik wrote:
> >
> > While the validating as you go sounds good, I think
> > there are some hard problems to be solved with it.
>
> Yes.
>
> > It would be nice to have a method (maybe on Document)
> > to cause validation to occur on a JDOM document.
>
> Yes.  Notice that's listed in TODO as a possible feature of JDOM 1.1.
>
> > I would be interested to hear where some of the
> > current maintainers stand on this.
>
> Happy to have it, but we need volunteers to work on implementing it.
>
> -jh-
>
>
> _______________________________________________
> To control your jdom-interest membership:
> http://lists.denveronline.net/mailman/options/jdom-interest/yourad
dr at yourhos
t.com

_______________________________________________
To control your jdom-interest membership:
http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@yourhos
t.com

_______________________________________________
To control your jdom-interest membership:
http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@yourhos
t.com




More information about the jdom-interest mailing list