You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xerces.apache.org by q3...@sneakemail.com on 2009/02/22 09:38:50 UTC

Distinguishing parse errors from validation errors

Hi there,

I'm using Xerces2-J to parse an XML document into a DOM. My application is
XML Schema aware, and the XML documents that my app is parsing are defined
via a schema.
When my application reads the XML document, it installs an ErrorHandler to
catch parsing errors. However, I noticed that schema validation errors are
caught by the very same interface (ErrorHandler.error(SAXParseException) and
friends), so I can't determine if the error was a validation error or a
parse error. The only possiblity I see to programmatically distinguish
between the two is to parse the error message string, which hardly seems
like a good solution to me.
Is there another interface that I can use that allows me to do some more
specific error handling?

Cheers,

Uwe

Re: Distinguishing parse errors from validation errors

Posted by Michael Glavassevich <mr...@ca.ibm.com>.
Hi Mukul,

Mukul Gandhi <ga...@gmail.com> wrote on 02/22/2009 08:51:37 AM:

> The class SAXParseException has a method, getSystemId() which can tell
> whether the fault occurred in the Schema or the XML document.

Might be useful to identify errors in the schema, however Uwe's question
was about distinguishing schema validation errors from other types of
errors which could be reported while processing the instance document.
Also, even for schema errors, getSystemId() isn't particularly reliable.
How can you tell from the URI what type of resource it's actually pointing
to?  It may not even have a value (e.g. schema document returned as an
InputStream).

> On Sun, Feb 22, 2009 at 2:08 PM,  <q3...@sneakemail.com> wrote:
> > Hi there,
> >
> > I'm using Xerces2-J to parse an XML document into a DOM. My application
is
> > XML Schema aware, and the XML documents that my app is parsing are
defined
> > via a schema.
> > When my application reads the XML document, it installs an ErrorHandler
to
> > catch parsing errors. However, I noticed that schema validation errors
are
> > caught by the very same interface
(ErrorHandler.error(SAXParseException) and
> > friends), so I can't determine if the error was a validation error or a
> > parse error. The only possiblity I see to programmatically distinguish
> > between the two is to parse the error message string, which hardly
seems
> > like a good solution to me.
> > Is there another interface that I can use that allows me to do some
more
> > specific error handling?

You can get more information through XNI. The XMLErrorHandler [1] interface
exposes a message key and domain which uniquely identifies each error.

> > Cheers,
> >
> > Uwe
>
> --
> Regards,
> Mukul Gandhi
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
> For additional commands, e-mail: j-users-help@xerces.apache.org

Thanks.

[1]
http://xerces.apache.org/xerces2-j/javadocs/xni/org/apache/xerces/xni/parser/XMLErrorHandler.html

Michael Glavassevich
XML Parser Development
IBM Toronto Lab
E-mail: mrglavas@ca.ibm.com
E-mail: mrglavas@apache.org

Re: Distinguishing parse errors from validation errors

Posted by Mukul Gandhi <ga...@gmail.com>.
The class SAXParseException has a method, getSystemId() which can tell
whether the fault occurred in the Schema or the XML document.

On Sun, Feb 22, 2009 at 2:08 PM,  <q3...@sneakemail.com> wrote:
> Hi there,
>
> I'm using Xerces2-J to parse an XML document into a DOM. My application is
> XML Schema aware, and the XML documents that my app is parsing are defined
> via a schema.
> When my application reads the XML document, it installs an ErrorHandler to
> catch parsing errors. However, I noticed that schema validation errors are
> caught by the very same interface (ErrorHandler.error(SAXParseException) and
> friends), so I can't determine if the error was a validation error or a
> parse error. The only possiblity I see to programmatically distinguish
> between the two is to parse the error message string, which hardly seems
> like a good solution to me.
> Is there another interface that I can use that allows me to do some more
> specific error handling?
>
> Cheers,
>
> Uwe



-- 
Regards,
Mukul Gandhi

---------------------------------------------------------------------
To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
For additional commands, e-mail: j-users-help@xerces.apache.org


Re: Distinguishing parse errors from validation errors

Posted by Stanimir Stamenkov <s7...@netscape.net>.
Sun, 22 Feb 2009 09:38:50 +0100, /q3s38w002@sneakemail.com/:

> I'm using Xerces2-J to parse an XML document into a DOM. My application 
> is XML Schema aware, and the XML documents that my app is parsing are 
> defined via a schema.
> When my application reads the XML document, it installs an ErrorHandler 
> to catch parsing errors. However, I noticed that schema validation 
> errors are caught by the very same interface 
> (ErrorHandler.error(SAXParseException) and friends), so I can't 
> determine if the error was a validation error or a parse error. The only 
> possiblity I see to programmatically distinguish between the two is to 
> parse the error message string, which hardly seems like a good solution 
> to me.
> Is there another interface that I can use that allows me to do some more 
> specific error handling?

Not Xerces specific, but you should probably get more familiar with 
the XML terminology [1].  "Parsing errors" are called 
well-formedness errors.  They are reported as fatal errors 
<http://www.saxproject.org/apidoc/org/xml/sax/ErrorHandler.html#fatalError(org.xml.sax.SAXParseException)>,
<http://java.sun.com/javase/6/docs/api/org/xml/sax/ErrorHandler.html#fatalError(org.xml.sax.SAXParseException)>,
<http://xerces.apache.org/xerces2-j/javadocs/api/org/xml/sax/ErrorHandler.html#fatalError(org.xml.sax.SAXParseException)>:

> Receive notification of a non-recoverable error.
> 
> This corresponds to the definition of "fatal error" in section 1.2 
> of the W3C XML 1.0 Recommendation. For example, a parser would use 
> this callback to report the violation of a well-formedness 
> constraint.

Xerces doesn't continue parsing after reporting a fatal error, by 
default.

Validation errors are re are reported as errors 
<http://www.saxproject.org/apidoc/org/xml/sax/ErrorHandler.html#error(org.xml.sax.SAXParseException)>, 
<http://java.sun.com/javase/6/docs/api/org/xml/sax/ErrorHandler.html#error(org.xml.sax.SAXParseException)>, 
<http://xerces.apache.org/xerces2-j/javadocs/api/org/xml/sax/ErrorHandler.html#error(org.xml.sax.SAXParseException)>:

> Receive notification of a recoverable error.
> 
> This corresponds to the definition of "error" in section 1.2 of the 
> W3C XML 1.0 Recommendation. For example, a validating parser would 
> use this callback to report the violation of a validity constraint.

[1] http://www.w3.org/TR/xml/#sec-terminology

-- 
Stanimir

---------------------------------------------------------------------
To unsubscribe, e-mail: j-users-unsubscribe@xerces.apache.org
For additional commands, e-mail: j-users-help@xerces.apache.org