xml transform problem...

V

Vlamos

Hello,

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
 
B

Brusque

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");
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,012
Latest member
RoxanneDzm

Latest Threads

Top