将xslt应用于castor marshaller输出流的最佳方法是什么?
我想在我的servlet中将xhtml发送到客户端。我也尝试在一个字符串中缓冲数据,并将一个管道放在一起到xalan,但这看起来很昂贵,并且应该有一种方法来处理流一次。
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String strGpxid = request.getParameter("id");
long gpxid = Long.parseLong(strGpxid);
// Set content type for HTML.
response.setContentType("text/xml; charset=UTF-8");
// Output goes to the response PrintWriter.
java.io.PrintWriter out = response.getWriter();
try
{ // private method call to fetch from gpxdb
Gpx gpx = this.getGpx(gpxid);
StringWriter strWriter = new StringWriter();
Marshaller marshaller = new Marshaller(strWriter);
marshaller.setEncoding("ISO-8859-1");
marshaller
.setSchemaLocation("http://www.topografix.com/GPX/1/1/gpx.xsd");
// marshaller.addProcessingInstruction(“xml-stylesheet”,“href ='gpsxmlQuickView.xsl'”);
PrintWriter pw = response.getWriter();
Marshaller.marshal(gpx, pw);
}
catch (Exception e)
{
out.write(e.getMessage());
e.printStackTrace(out);
}
out.close();
}
TIA