Comments get clobbered in transformation

C

Collin VanDyck

I'm a semi-newbie to XSL transformations, so hopefully you guys can tell me
what I'm doing wrong here. I have a string that is an XML document that I
am running through a Xalan transformer:

public String transform (String pageXML) throws SAXException , IOException {
XMLReader reader = XMLReaderFactory.createXMLReader();

ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
Properties p = OutputProperties.getDefaultMethodProperties("xml");
Serializer serializer = SerializerFactory.getSerializer(p);
serializer.setOutputStream(outputStream);

this.setParent(reader);
this.setContentHandler(serializer.asContentHandler());

InputSource input = new InputSource(new StringReader(new
String(pageXML)));
this.parse(input);

String toReturn = outputStream.toString();
return toReturn;

Note: 'this' is a subclass of XMLFilterImpl. In the source XML, I have a
SSI like this:

<!--#include /path/file.asp-->

This is getting erased somehow in the transformation. I suspect that it has
something to do with the Properties object I am using to create my
Serializer. Is there some property I need to set to allow comments?
Also, I could not find a reference in my Googling for a list of the possible
output properties. I think I'm missing something pretty simple here.

I tested this with an empty class of XMLFilterImpl, with the same results,
so I know it is not my SAX event overrides causing this problem.

Thanks in advance!
 
P

Patrick TJ McPhee

% I'm a semi-newbie to XSL transformations, so hopefully you guys can tell me
% what I'm doing wrong here.

It's difficult to tell what you're doing wrong if you don't post the
actual transformation. The most likely thing is that you aren't copying
the comment (which you're using as if it were a processing instruction)
(a pet peeve of mine) to the result tree.
 
C

Collin VanDyck

I found that by creating a class that implements LexicalHandler, and setting
the XML Reader as such:

reader.setProperty("http://xml.org/sax/properties/lexical-handler",new
LexicalHandlerImpl());

I actually get the comments! However, I am still stuck on how to get them
back into the result tree. Ideas?

TIA
Collin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top