I have a servlet that transforms a XML and XSL file into a HTML page.
So the servlet uses 2 files on the server. Now I want to use an XML
file that is generated by a php script on a different server.
This is a part of the code :
public void transformToHtml(String xmlFileName, HttpServletResponse res) {
try {
//create xmlSource
Source xmlSource = new StreamSource(xmlFileName);
PrintWriter out = res.getWriter();
//do the actual transformation on the XML source and
//send output through ServletOutputStream
transformer.setOutputProperty(OutputKeys.METHOD, "xml");
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
transformer.transform(xmlSource, new StreamResult(out));
} catch (TransformerConfigurationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (TransformerException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
So the transformToHTML takes a xmlfile and the servlet response to write
to... But how can I use an URL as file? Do I have to retrieve the file,
store it as a XML file and transform it?
Thanks !
Tom
A StreamSource can take a String URL as its argument.
Source source = new StreamSource("http://www.something.com/test.xml");