This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
xslt servlet that uses foo.xml and rewrites foo.xml
- To: <xsl-list at lists dot mulberrytech dot com>
- Subject: [xsl] xslt servlet that uses foo.xml and rewrites foo.xml
- From: "Robert Koberg" <rob at koberg dot com>
- Date: Sun, 29 Apr 2001 07:44:19 -0700
- References: <20010429111243.14670.qmail@web12607.mail.yahoo.com>
- Reply-To: xsl-list at lists dot mulberrytech dot com
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