[jdom-interest] DOMBuilder validation
Brett McLaughlin
brett.mclaughlin at lutris.com
Wed Jun 14 08:47:48 PDT 2000
Elliotte Rusty Harold wrote:
>
> At 10:30 PM -0700 6/13/00, Jason Hunter wrote:
>
> >The code looks like it should be validating, and someone else posted
> >that they saw validation occurring. Are you sure you're not seeing
> >validation? Are you using the default-provided Xerces?
> >
>
> I've tried this with multiple builds of Xerces. All give me the same
> result. Maybe the flaw is in my understanding of how validity errors
> are reported. With SAXBuilder a validity error throws an exception at
> build time. Does this not happen with DOMBuilder? If so, how is one
> supposed to note the validity errors?
For the record, Elliotte, I think there may be validation problems in
DOMBuilder - that class has not gotten as much attention as SAXBuilder
has, for obvious reasons. I'll take a look today and get back to you...
-Brett
>
> Here's the code I'm working with. The SAXBuilder equivalent works just fine.
>
> import org.jdom.*;
> import org.jdom.input.DOMBuilder;
> import org.apache.xerces.parsers.*;
>
> public class DOMValidator {
>
> public static void main(String[] args) {
>
> if (args.length == 0) {
> System.out.println("Usage: java DOMValidator URL1 URL2...");
> }
>
> DOMBuilder builder = new DOMBuilder(true);
> /* ^^^^ */
> /* Turn on validation */
> // start parsing...
> DOMParser parser = new DOMParser(); // Xerces specific class
> for (int i = 0; i < args.length; i++) {
>
> try {
> // Read the entire document into memory
> parser.parse(args[i]);
>
> org.w3c.dom.Document domDoc = parser.getDocument();
> org.jdom.Document jdomDoc = builder.build(domDoc);
>
> // If there are no validity errors,
> // then no exception is thrown
> System.out.println(args[i] + " is valid.");
> }
> catch (Exception e) { // indicates a well-formedness or validity error
> System.out.println(args[i] + " is not valid.");
> System.out.println(e.getMessage());
> }
>
> }
>
> }
>
> }
>
> +-----------------------+------------------------+-------------------+
> | Elliotte Rusty Harold | elharo at metalab.unc.edu | Writer/Programmer |
> +-----------------------+------------------------+-------------------+
> | The XML Bible (IDG Books, 1999) |
> | http://metalab.unc.edu/xml/books/bible/ |
> | http://www.amazon.com/exec/obidos/ISBN=0764532367/cafeaulaitA/ |
> +----------------------------------+---------------------------------+
> | Read Cafe au Lait for Java News: http://metalab.unc.edu/javafaq/ |
> | Read Cafe con Leche for XML News: http://metalab.unc.edu/xml/ |
> +----------------------------------+---------------------------------+
> _______________________________________________
> 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