Sun, 22 Feb 2009 09:38:50 +0100, /q3s38w...@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-unsubscr...@xerces.apache.org
For additional commands, e-mail: j-users-h...@xerces.apache.org

Reply via email to