[jdom-interest] schema validation for xml document through jdom

Jon Baer jonbaer at digitalanywhere.com
Thu Mar 15 11:51:55 PST 2001


What is discussed in this article is more about the contraints of a servlets
parameters via XML Schema but this same approach is not (or does not seem able to
work with JDOM).  I have the lightweight DTD parser that was pointed out by Rusty a
while ago by Mark Wutka and have played around with it where the DTD will parse out
what the valid attribs and children are for all the elements (in an array).

I think where this needs to be included is in the building process, for example:

Take a DTD, parse the info (using the lightweight parser) and if validation is on
then attempt to build the document while running through the array to see if an
Element build or Attribute build is valid or not.  Then you can subclass the
exceptions to InvalidElementException, InvalidChildException,
InvalidAttributeException, etc, will hopefully some useful information.

try {
SAXBuilder b = new SAXBuilder();
Document d = b.build(new FileInputStream("file.xml"));
}
catch (DTDException e) {
    System.out.println("Error building document: " + e.getMessage());
}

Paul Sanford Friedman wrote:

> Hello,
>     The following is a link to a JavaWorld article by Brett that deals with
> data validation with Java and XMLSchema using JDOM.
>     It may or may not suit your purposes but is a decent read for dealing
> with XML validation.
> http://www.javaworld.com/javaworld/jw-09-2000/jw-0908-validation.html
>     Hope it helps you.
>     And thanks to Brett for the info in the first place.
>
> pax et bonum. p.
>
> ----- Original Message -----
> Subject: [jdom-interest] schema validation for xml document through jdom
>
> > Hi all,
> > Is there any way to do schema validation of an xml document when jdom is
> > used to read the document. I know there is a validation flag but it only
> > checks for DTD if I am not mistaken. I only have schema ----- no DTD ----
> > would it be possible for me to do schema validation?
> >
> > Thanks,
> >
> > Sibon Barman
> > SS8 Networks, Inc.
> > Suite 500
> > 495 March Road, Kanata,
> > Ontario K2K 3G1
> >
> > *: (613)592-2100 ext:3281
> > *: sibon at ss8.com
> >
>
> _______________________________________________
> To control your jdom-interest membership:
> http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@yourhost.com




More information about the jdom-interest mailing list