xerces-j-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Michael Glavassevich <mrgla...@ca.ibm.com>
Subject Re: How to get exact location of schema validation errors?
Date Mon, 27 Oct 2008 20:59:06 GMT

Hi Alex,

The current element node being visited by the Validator can be queried [1]
from your error handler by calling back into it with getProperty() [2].

Thanks.

[1]
http://xerces.apache.org/xerces2-j/properties.html#dom.current-element-node
[2]
http://xerces.apache.org/xerces2-j/javadocs/api/javax/xml/validation/Validator.html#getProperty(java.lang.String)

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

Alex Talis <alex.talis@yahoo.com> wrote on 10/27/2008 01:28:12 PM:

> Hi, Mukul
>
> Thanks for your response, but I'm not looking for column and row
> numbers in the XML document.  I might have been a little ambiguous
> in using the word "location".  What I need is the reference to the
> Node object in the DOM tree that caused the validation error.  The
> perfect solution would be for the SAXException to contain a
> reference to that Node.
>
> I started looking at the source of org.apache.xerces.impl.xs.
> XMLSchemaValidator, and I see a method called processOneAttribute,
> which has all this info for attributes.  There is also code that
> deals with Elements and also has the references to Nodes.  I'm going
> to study this a little and see if I can do something with it.
>
> Alex
>
> ----- Original Message ----
> From: Mukul Gandhi <gandhi.mukul@gmail.com>
> To: j-users@xerces.apache.org
> Cc: Alex Talis <alex.talis@yahoo.com>
> Sent: Sunday, October 26, 2008 8:36:26 PM
> Subject: Re: How to get exact location of schema validation errors?
>
> On Mon, Oct 27, 2008 at 7:07 AM, Alex Talis <alex.talis@yahoo.com> wrote:
> > I'm using JAXP to validate a DOM Document with a Validator.  When
validation
> > fails, I get an exception with a pretty descriptive message, but no way
to
> > pinpoint where in the document the error was found.
>
> You can set an error handler to a validator.
>
> for e.g.,
>
> Validator validator = schema.newValidator();
> MyErrorHandler errorHandler = new MyErrorHandler();
> validator.setErrorHandler(errorHandler);
> validator.validate(new DOMSource ...
>
> Then in MyErrorHandler, you should write as,
>
> class MyErrorHandler implements ErrorHandler {
>
>   public void fatalError(SAXParseException e) throws SAXException {
>
>   }
>
>   public void error(SAXParseException e) throws SAXException {
>
>   }
>
>   public void warning(SAXParseException e) throws SAXException {
>
>   }
>
> within the methods, fatalError, error or warning, you can get location
> of the error/problem as,
>
> e.getLineNumber()
> e.getColumnNumber()
>
>
> --
> Regards,
> Mukul Gandhi
Mime
View raw message