[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Using a TransformerHandler strips comments but a Tran

Subject: Using a TransformerHandler strips comments but a Transformer keeps them
From: "Andrew Welch" <andrew.j.welch@xxxxxxxxx>
Date: Wed, 13 Feb 2008 10:54:02 +0000
 Using a TransformerHandler strips comments but a  Tran
Does anyone know why a transform using a TransformerHandler strips
comments but the "stardard" Tranformer keeps them.

For example:

sourceXML:

<?xml version="1.0" encoding="UTF-8"?>
<!-- test outer comment -->
<foo> <!-- inner comment --> foo</foo>

The stylesheet is the identity transform.

The first transformation technique is using a TransformerHandler:

SAXTransformerFactory stf =
(SAXTransformerFactory)TransformerFactory.newInstance();;
TransformerHandler handler = stf.newTransformerHandler(new
StreamSource(stylesheet));
handler.setResult(new StreamResult(System.out));
XMLReader xmlReader = XMLReaderFactory.createXMLReader();
xmlReader.setContentHandler(handler);
xmlReader.parse(sourceXML.toURI().toString());

The second is using a Transformer:

stf.newTransformer(new StreamSource(stylesheet)).
		transform(new StreamSource(sourceXML), new StreamResult(System.out));

Produces this output:

TransformerHandler:
<?xml version="1.0" encoding="UTF-8"?><foo>  foo</foo>

Transformer:
<?xml version="1.0" encoding="UTF-8"?><!-- test outer comment --><foo>
<!-- inner comment --> foo</foo>


I would expect the two to produce identical results.  Has anyone come
across this before?


thanks
andrew

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.