[jdom-interest] Newbie: Schema validation of a document being built via JDOM
Paul Jakubik
pauljakubik at yahoo.com
Mon Mar 19 07:04:24 PST 2001
While the validating as you go sounds good, I think
there are some hard problems to be solved with it.
If the document has lots of required elements, your
validation should fail until you have added all the
required elements. Should you get an exception each
time you add an element until you have added
everything necessary?
If you relax the validation so it doesn't complain
about missing elements, what do you do when you add a
complex element, and it is missing some necessary
fields. Without getting the exception immediately you
may never know that the document is invalid because it
is missing some subelement.
Finally, so far JDOM has stayed out of the validation
business. Currently validation is the job of the
parser.
It would be nice to have a method (maybe on Document)
to cause validation to occur on a JDOM document. Then
the user can decide when they think they have the
document in a state that should validate correctly and
only validate then (you may have to make several
modifications to a document to get from one valid
state to another). Adding this method may be a
violation of the basic policy of leaving validation to
the parsers (or it may at least require specifying how
to parse the document similar to what you specify when
building a document).
I would be interested to hear where some of the
current maintainers stand on this.
--Paul
--- "Steven D. Keens" <skeens at planetfred.com> wrote:
> You know, I think this is a great idea. I find that
> I do a bit of runtime validation when building my
> JDOM
> trees. Particularly when the tree is built via a
> collaboration of many objects. I'm a defensive
> programmer
> so I probably do more validation than most people.
> With
> your idea I would just wrap my tree building in a
> try/catch
> statement and catch the JDOMInvalidException
> (whatever it's called).
>
>
> -----Original Message-----
> From: jdom-interest-admin at jdom.org
> [mailto:jdom-interest-admin at jdom.org]On Behalf Of
> John Methot
> Sent: Friday, March 16, 2001 20:06
> To: 'jdom-interest at jdom.org'
> Subject: [jdom-interest] Newbie: Schema validation
> of a document being
> built via JDOM
>
>
> I've read back through the archives since November
> for all
> validation-related topics. I see a lot of questions
> about validating
> documents that are being read.
>
> My interest is in using JDOM to create documents
> programmatically. But I
> don't see anything in the javadoc or tutorials on
> JDOM that say I can
> validate a document as I'm building it. I can
> specify a systemID (a DTD or,
> preferably, a schema) when I create a Document
> object. But then it would
> seem useful if when I called Element.addAttribute()
> or Element.addElement()
> (for example) I would get an exception if I tried to
> add an attribute or
> child element that violated the schema.
>
> I'm pretty sure this isn't there now (please correct
> me if it is and I'm
> missing it).
>
> The only approach I can see right now is to build
> the entire document and
> then validate it by parsing the whole thing, but
> that wouldn't give me much
> visibility into the structural errors as they occur.
>
> Anybody else have the desire to validate a document
> as it is built? Am I
> thinking about this all wrong?
>
> TIA,
>
> John Methot
>
> _______________________________________________
> 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@yourhost.com
__________________________________________________
Do You Yahoo!?
Get email at your own domain with Yahoo! Mail.
http://personal.mail.yahoo.com/
More information about the jdom-interest
mailing list