Hello,
 
for a Web App I wrote a serializer component that transforms a DOM with a 
Stylesheet if the Client Browser is not xsl capable. Otherwise it includes a 
ProcessingInstruction into the DOM and just serializes it.
Now - what is the best way to seralize a DOM to a ServletOutputStream ?
 
I've got two working variants:
 
1: using identity-Transformer
 
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.Transformer;
...
http_servlet_response.setContentType("text/xml");
Transformer transformer = TransformerFactory.getInstance().newTransformer();
transformer.transform(new DOMSource(document), new 
StreamResult(http_servlet_response.getOutputStream()));
 
2. using SerializerToXML
...
import org.apache.xalan.serialize.SerializerToXML;
 
SerializerToXML serializer = new SerializerToXML();
serializer.setOutputStream(http_servlet_response.getOutputStream());
serializer.serialize(document);
 
I guess the second solution sets the encoding so i don't have to do it (i'm not 
sure if i should set it).
What are the other differences if there are some ? Maybe i should use xsltc 
here ? 
 
Stefan
 
Btw.
I've read the other postings concerning serialization but i'm still in doubt 
what to use :-(

Reply via email to