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

Eric M. Burke burke_e at yahoo.com
Sun Mar 18 10:02:47 PST 2001


I don't think what you are asking for is even
possible. Consider a situation where the following
structure is required:

As you were constructing the <person> element,
however, you would get a validation exception
because the first and last names, both of
which are required, have not been added to
the document yet. This is a "chicken and egg"
problem. Most documents cannot be valid
until they are fully constructed. But if the
parser throws a bunch of exceptions as the
documents are being created, you would never
be able to fully construct them.

Another problem is that JDOM doesn't do validation.
It merely delegates to the underlying parser
implementation, such as Crimson or Xerces, to
do the validation work. Since those parsers don't
do validation that way, JDOM doesn't.

> -----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 7:06 PM
> 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/yourad
dr at yourhost.com

More information about the jdom-interest mailing list