xsl-list
[Top] [All Lists]

Re: [xsl] Using a TransformerHandler strips comments but a Transformer keeps them

2008-02-13 04:13:42
Andrew Welch wrote:

Does anyone know why a transform using a TransformerHandler strips
comments but the "stardard" Tranformer keeps them.

[snipped]
XMLReader xmlReader = XMLReaderFactory.createXMLReader();
xmlReader.setContentHandler(handler);
xmlReader.parse(sourceXML.toURI().toString());

Hi Andrew,

You need to tell your XMLReader to forward lexical events (e.g. comments) to the TransformerHandler as well. In what you have above, you have only asked it to forward basic ContentHandler-type SAX events onwards.

Add the following after your setContentHandler() line:

xmlReader.setProperty("http://xml.org/sax/properties/lexical-handler";,
                        hander);

and you should find your comments reappearing.

There's more info in the JavaDoc for org.xml.sax.ext.LexicalHandler

Cheers,
Dave.

--
David McKain http://www.ph.ed.ac.uk/~dmckain/
School of Physics e-Learning Group http://www.ph.ed.ac.uk/elearning/

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--