I guess from your description you are talking specifically about XML errors in a stylesheet document, especially an included/imported stylesheet document?

It would be useful to know how you are actually parsing the stylesheet. Are you using JAXP or s9api? Did you set either a stylesheetParser or a URIResolver on the Configuration as well as setting an ErrorListener?

There are some circumstances in which Saxon will attach a SAX ErrorHandler to the XMLReader that directs the errors in turn to the user's ErrorListener, but there are also cases where it doesn't - if the user has attached their own ErrorHandler, then we don't want to disturb that. So it depends on the exact circumstances. Meanwhile, as a workaround, you should be able to use a URIResolver that returns a SAXSource initialized to use your own XMLReader and your own SAX ErrorHandler, and Saxon should respect that and not switch it to its own.

Michael Kay
Saxonica

On 21/11/2010 04:48, Todd Gochenour wrote:
I've written an ErrorListener and attached it to both net.sf.saxon.TransformerFactoryImpl and the transformer created by the factory.  I catch XSL syntax errors just fine.  Yet errors in XML structure (missing/extra tag, etc.) cause a SXX0003 XML parse error which is not caught by the error listener. This error is printed in the error console.  I need to capture this error and display the reason for the error to the developer writing/testing the XSL.  Odd thing is, when a single imported template can't be parsed, the other XSL files are still loaded and parsed so that a whole slew of unrelated errors are thrown because of the missing imported template.  The real reason for this (the XML can't be parsed) is the one reason not sent to the error listener.  Is there a way to capture these messages?

The code:

    ArrayList<TransformerException> errorList = new ArrayList<TransformerException>();
    ErrorListener listener = new ErrorListener() {
       
        public void error(TransformerException exception) throws TransformerException
        {
            Log logger = LogFactory.getLog(MODE.toUpperCase());
            logger.error("TRANSFORMXML ERROR:"+exception.getMessageAndLocation());
            errorList.add(exception);
        }

        public void fatalError(TransformerException exception) throws TransformerException
        {
            Log logger = LogFactory.getLog(MODE.toUpperCase());
            logger.fatal("TRANSFORMXML ERROR:"+exception.getMessageAndLocation());
            errorList.add(exception);
            throw exception;
        }

        public void warning(TransformerException exception) throws TransformerException
        {
            Log logger = LogFactory.getLog(MODE.toUpperCase());
            logger.warn("TRANSFORMXML WARNING:"+exception.getMessageAndLocation());
            errorList.add(exception);
        }
    };
   
    try
    {
        tranFactory = new net.sf.saxon.TransformerFactoryImpl(SAXON_CONFIGURATION);
        tranFactory.setErrorListener(listener);
        aTransformer = tranFactory.newTransformer( source );
        aTransformer.setErrorListener(listener);
    }
    catch( javax.xml.transform.TransformerException e1 )
    {
        handleException(e1);
    }


------------------------------------------------------------------------------ Beautiful is writing same markup. Internet Explorer 9 supports standards for HTML5, CSS3, SVG 1.1, ECMAScript5, and DOM L2 & L3. Spend less time writing and rewriting code and more time creating great experiences on the web. Be a part of the beta today http://p.sf.net/sfu/msIE9-sfdev2dev
_______________________________________________ saxon-help mailing list archived at http://saxon.markmail.org/ saxon-help@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/saxon-help