You are viewing a plain text version of this content. The canonical link for it is here.
Posted to general@xml.apache.org by Ja...@jba.co.uk on 2000/04/06 17:24:46 UTC

Required - example java code to demonstrate error reporting

Now that XML Schemas are replacing DTD's I've started use
the Xerces Java Parser 1.0.3 but in my java class, when I parse my XML
document (which has a schema associated in it),
only syntactic errors are detected  by a SAXException being thrown - such
as a tag without an end tag - these can be detected in both the XML Schema
and the base XML,
but I am unable to detect other errors such as an element that has
minOccurs='2', but it is only occurs once.

I have tried looking for examples and but none of them appear to go into
enough detail. The only information I can get is to
use  the DOMParser  setFeature( "http://xml.org/sax/features/validation",
true) method, but this gives that problem described
above.

When I used DTD's I used to check that whether the XML document had been
validated by using
the Parser methods getNumberOfErrors() or getNumberOfWarnings().
Has anyone go an example of some java code doing the equivalent type of
thing with schemas.

Thank you
Jayne



RE: Required - example java code to demonstrate error reporting

Posted by Dwayne Schultz <Dw...@Schultz.net>.
> From: Jayne_Peachey@jba.co.uk [mailto:Jayne_Peachey@jba.co.uk]
> 
> Now that XML Schemas are replacing DTD's I've started use
> the Xerces Java Parser 1.0.3 but in my java class, when I parse my XML
> document (which has a schema associated in it),
> only syntactic errors are detected  by a SAXException being 
> thrown - such
> as a tag without an end tag - these can be detected in both 
> the XML Schema
> and the base XML,
> but I am unable to detect other errors such as an element that has
> minOccurs='2', but it is only occurs once.
> 

Did you register an error handler?

ErrorHandler errorHandler = new ErrorHandler() {
    public void fatalError(SAXParseException exception)
        throws SAXException {
        throw exception;
    }
    public void error(SAXParseException exception)
        throws SAXException {
        throw exception;
    }
    public void warning(SAXParseException exception)
        throws SAXException {
        exception.printStackTrace();
    }
};
parser.setErrorHandler(errorHandler);