|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] xslt servlet that uses foo.xml and rewrites foo.xml
Hi,
I am trying to write a servlet that takes an XML file transforms that file
and rewrites it. When I try the code below I get a malformed document
exception (no root element) because the document (Result I assume) is
prepared for writing??? by having everything deleted form it.
How can I write a simple servlet that rewrites the source document? How can
I get the the StreamSource into a variable so I can transform it back into
the original file?
Note: if I write out to a new file there is no problem with the
transformation.
-----------------------------------
public class AddPage extends HttpServlet {
public void doPost(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
res.setContentType("text/plain");
PrintWriter out = res.getWriter();
String xmlref = "c:/resin/doc/ed/xml/config.xml";
String xslref = "c:/resin/doc/ed/xml/addpage.xsl";
String parentElem = req.getParameter("parentElem");
try {
TransformerFactory tFactory = TransformerFactory.newInstance();
Transformer transformer = tFactory.newTransformer(new
StreamSource(xslref));
transformer.setParameter("id",parentElem);
StreamSource strmsrc = new StreamSource(xmlref);
//StreamResult strmrslt = new StreamResult(xmlref);
transformer.transform (strmsrc, new StreamResult(xmlref));
}
catch (Exception e) {
out.write(e.getMessage());
e.printStackTrace(out);
}
out.close();
}
---------------------------
Thanks,
Rob
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








