You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-dev@xmlgraphics.apache.org by Finn Bock <bc...@worldonline.dk> on 2004/10/21 14:34:50 UTC

Handling XML parse errors when using identity transform.

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:

<?xml version="1.0" encoding="UTF-8"?>
<xfo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
</xfo:root>

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

Re: Handling XML parse errors when using identity transform.

Posted by "J.Pietschmann" <j3...@yahoo.de>.
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.

Posted by Finn Bock <bc...@worldonline.dk>.
[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.

Posted by Glen Mazza <gr...@yahoo.com>.
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 <bc...@worldonline.dk> 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:
> 
> <?xml version="1.0" encoding="UTF-8"?>
> <xfo:root
> xmlns:fo="http://www.w3.org/1999/XSL/Format">
> </xfo:root>
> 
> 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
> 


Re: Handling XML parse errors when using identity transform.

Posted by Glen Mazza <gr...@yahoo.com>.
--- Finn Bock <bc...@worldonline.dk> 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.

Posted by "Andreas L. Delmelle" <a_...@pandora.be>.
> -----Original Message-----
> From: Andreas L. Delmelle [mailto:a_l.delmelle@pandora.be]

> [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.

Posted by "Andreas L. Delmelle" <a_...@pandora.be>.
> -----Original Message-----
> From: Finn Bock [mailto:bckfnn@worldonline.dk]

> >
> > 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...
<snip />
[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.

Posted by Finn Bock <bc...@worldonline.dk>.
[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.

Posted by "Andreas L. Delmelle" <a_...@pandora.be>.
> -----Original Message-----
> From: Finn Bock [mailto:bckfnn@worldonline.dk]
>

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:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <xfo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
> </xfo:root>
>
> 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