You are viewing a plain text version of this content. The canonical link for it is here.
Posted to general@xerces.apache.org by ki...@prusec.com on 2000/02/23 20:18:36 UTC

[Xerces-J] XMLSchemaValidator and errors....

Hey... I'm currently working with XML schemas to validate data input on the
client (a bit of a different use). Consequently, when I validate a
document, I want an immediate response if there is  problem (via an
exception or a return code or something). My org.xml.sax.ErrorHandler
implementation simply throws any exception it gets, and I expected these
exceptions to be thrown from the parser's parse() method. The result,
however, is that the XMLSchemaValidator catches it in  the loadSchema()
method, and prints out the stack trace. Is this really the desirable
behavior? It seems to me that most people would want the ability to catch
their exceptions, should they choose to throw them from the error handler
(especially since parse() throws a SAXException). Also, if there's a
problem loading the schema, shouldn't we have the option to respond in some
way? Since loadSchema() just prints out exceptions and error messages, this
doesn't appear to be possible.

Someone please let me know if I'm totally off base, or if there's a way to
do what I'd like to do.

Kito D. Mann
kmann@virtua.com



RE: [Xerces-J] XMLSchemaValidator and errors....

Posted by "George T. Joseph" <gt...@peakin.com>.
I submitted a patch for this on 2/1 but it was bundled with 2 other more
controversial  patches and never got applied.  A standalone patch to remove the
try/catch blocks is appended.

george

-----Original Message-----
From: Andy Clark [mailto:andyc@apache.org]
Sent: Wednesday, February 23, 2000 6:51 PM
To: xerces-dev@xml.apache.org
Subject: Re: [Xerces-J] XMLSchemaValidator and errors....


kito_mann@prusec.com wrote:
> exceptions to be thrown from the parser's parse() method. The result,
> however, is that the XMLSchemaValidator catches it in  the loadSchema()
> method, and prints out the stack trace. Is this really the desirable

You are completely correct, this should be changed. Our schema
support at the moment it experimental but in the final implementation
errors in loading the schema should be reported through the error
handler registed on the parser.

--
Andy Clark * IBM, JTC - Silicon Valley * andyc@apache.org


diff -u XSchemaValidator.bak XSchemaValidator.java
--- XSchemaValidator.bak	Mon Feb 07 22:11:00 2000
+++ XSchemaValidator.java	Thu Feb 24 10:29:00 2000
@@ -1658,7 +1658,7 @@

     private DOMParser fSchemaParser = null;

-    public void loadSchema(InputSource is) {
+    public void loadSchema(InputSource is) throws Exception{

         // create parser for schema
         if (fSchemaParser == null) {
@@ -1670,38 +1670,12 @@
             fSchemaParser.setErrorHandler(new ErrorHandler());
         }

-        // parser schema file
-        try {
-
-            fSchemaParser.setFeature("http://xml.org/sax/features/validation",
true);
-
fSchemaParser.setFeature("http://apache.org/xml/features/dom/defer-node-expansio
n", false);
-            fSchemaParser.parse(is);
-        }
-        catch (SAXException se) {
-            se.getException().printStackTrace();
-            System.err.println("error parsing schema file");
-//            System.exit(1);
-        }
-        catch (Exception e) {
-            e.printStackTrace();
-            System.err.println("error parsing schema file");
-//            System.exit(1);
-        }
+        fSchemaParser.setFeature("http://xml.org/sax/features/validation",
true);
+
fSchemaParser.setFeature("http://apache.org/xml/features/dom/defer-node-expansio
n", false);
+        fSchemaParser.parse(is);
         fSchemaDocument = fSchemaParser.getDocument();
-        if (fSchemaDocument == null) {
-            System.err.println("error: couldn't load schema file!");
-            return;
-        }
-
-        // traverse schema
-        try {
-            Element root = fSchemaDocument.getDocumentElement();
-            traverseSchema(root);
-        }
-        catch (Exception e) {
-            e.printStackTrace(System.err);
-//            System.exit(1);
-        }
+        Element root = fSchemaDocument.getDocumentElement();
+        traverseSchema(root);
     }

     private void traverseSchema(Element root) throws Exception {


Re: [Xerces-J] XMLSchemaValidator and errors....

Posted by Andy Clark <an...@apache.org>.
kito_mann@prusec.com wrote:
> exceptions to be thrown from the parser's parse() method. The result,
> however, is that the XMLSchemaValidator catches it in  the loadSchema()
> method, and prints out the stack trace. Is this really the desirable

You are completely correct, this should be changed. Our schema
support at the moment it experimental but in the final implementation
errors in loading the schema should be reported through the error
handler registed on the parser.

-- 
Andy Clark * IBM, JTC - Silicon Valley * andyc@apache.org