Re: Handling XML parse errors when using identity transform.
--- Finn Bock <[EMAIL PROTECTED]> wrote: > > I couldn't get that working. As I see the it, the > SAXException from the > xml parsing is not passed through to the > ErrorListener. > > The source code from xalan confirms that. No > ErrorHandler is passed to > the XMLReader that is create in > TransformerIdentityImpl.java. > > regards, > finn > Probably best to just enter a Bugzilla report for Xalan. Glen
Re: Handling XML parse errors when using identity transform.
Finn Bock wrote: and there is no way AFAICT to set a different error handler on the XMLReader that the xalans transformer creates and uses to parse the input file. Well, if you really need control over the parser, you have to create one by yourself rather than relying on StreamSource to do it for you. You can cast the TransformerFactory instance into a SAXTransformerFactory in order to get a filter which you can pass to the parser instance as content handler. Look into Cocoon's XSLTransformer component for a comprehensive example, and I'm sure the Xalan docs have even easier to grok sample code. Alternatively, you can - parse into a DOM and use a DOMSource, if you don't mind the potential memory overhead. - derive a custom class from SAXSource which sets up a properly custiomized parser instance, if you don't mind the programming overhead. J.Pietschmann
RE: Handling XML parse errors when using identity transform.
> -Original Message- > From: Andreas L. Delmelle [mailto:[EMAIL PROTECTED] > [Finn:] > > I couldn't get that working. As I see the it, the SAXException from the > > xml parsing is not passed through to the ErrorListener. > > > > The source code from xalan confirms that. No ErrorHandler is passed to > > the XMLReader that is create in TransformerIdentityImpl.java. > > > The more I think about it --Cute! so: TransformerIdentityImpl has setErrorListener(), being extended from Transformer org.xml.sax.XMLReader() has setErrorHandler() Someone's definitely not using them appropriately (?-- Xalan?) To think that this may all boil down to one line of code missing: reader.setErrorHandler( (ErrorHandler) this.getErrorListener() ); ;-P Cheers, Andreas
RE: Handling XML parse errors when using identity transform.
> -Original Message- > From: Finn Bock [mailto:[EMAIL PROTECTED] > > > > Not sure if this is what you're looking for, but the > > javax.xml.transform.Transformer class does offer a setErrorListener() method > > to use a custom Error Handler... [Finn:] > I couldn't get that working. As I see the it, the SAXException from the > xml parsing is not passed through to the ErrorListener. > > The source code from xalan confirms that. No ErrorHandler is passed to > the XMLReader that is create in TransformerIdentityImpl.java. > Hmm.. Indeed a problem. I'm thinking: what happens when you perform an identity transform via XSLT (i.e. considering FO input to be a special case of XML input --where the XSL defaults to a supplied stylesheet that performs an identity transform on the FO source)? So I just tried that, and there is a noticeable difference in the error reporting: the '[Fatal Error]' message disappears. Greetz, Andreas
Re: Handling XML parse errors when using identity transform.
[Andreas] Hi Finn, Not sure if this is what you're looking for, but the javax.xml.transform.Transformer class does offer a setErrorListener() method to use a custom Error Handler... IIUC, all we have yet to do is provide an implementation for a javax.xml.transform.ErrorListener and use it to route the error messages to our common-logging (instead of the org.apache.xml.utils.DefaultErrorHandler routing them to stderr or a supplied PrintStream or PrintWriter). I couldn't get that working. As I see the it, the SAXException from the xml parsing is not passed through to the ErrorListener. The source code from xalan confirms that. No ErrorHandler is passed to the XMLReader that is create in TransformerIdentityImpl.java. regards, finn
RE: Handling XML parse errors when using identity transform.
> -Original Message- > From: Finn Bock [mailto:[EMAIL PROTECTED] > Hi Finn, Not sure if this is what you're looking for, but the javax.xml.transform.Transformer class does offer a setErrorListener() method to use a custom Error Handler... IIUC, all we have yet to do is provide an implementation for a javax.xml.transform.ErrorListener and use it to route the error messages to our common-logging (instead of the org.apache.xml.utils.DefaultErrorHandler routing them to stderr or a supplied PrintStream or PrintWriter). > I'm no expert on java's xml & transformer APIs so I need a little help. > It appears to me that when using the identity Transformer from xalan we > no longer get notifications of XML parse errors. > > Using an obviously corrupt input fo: > > > http://www.w3.org/1999/XSL/Format";> > > > we get the a message on stderr from xerces DefaultErrorHandler: > > [Fatal Error] t.fo:2:56: The prefix "xfo" for element "xfo:root" is not > bound. > > and there is no way AFAICT to set a different error handler on the > XMLReader that the xalans transformer creates and uses to parse the > input file. > > Am I missing something? > > regards, > finn > HTH, Andreas
Re: Handling XML parse errors when using identity transform.
[Glen] I'm not sure of the problem here, your input fo is not an xsl fo, because the xfo to a namespace wasn't bound. Hence the Xerces error message--what is it that you're expecting instead? I would expect that the ErrorHandler methods in FOTreeBuilder (warning(), error() and fatalError()) was called. And that the message was written to our common-logging. regards, finn
Re: Handling XML parse errors when using identity transform.
I'm not sure of the problem here, your input fo is not an xsl fo, because the xfo to a namespace wasn't bound. Hence the Xerces error message--what is it that you're expecting instead? Glen --- Finn Bock <[EMAIL PROTECTED]> wrote: > Hi Team, > > I'm no expert on java's xml & transformer APIs so I > need a little help. > It appears to me that when using the identity > Transformer from xalan we > no longer get notifications of XML parse errors. > > Using an obviously corrupt input fo: > > > xmlns:fo="http://www.w3.org/1999/XSL/Format";> > > > we get the a message on stderr from xerces > DefaultErrorHandler: > > [Fatal Error] t.fo:2:56: The prefix "xfo" for > element "xfo:root" is not > bound. > > and there is no way AFAICT to set a different error > handler on the > XMLReader that the xalans transformer creates and > uses to parse the > input file. > > Am I missing something? > > regards, > finn >