Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

xml transform problem...

1 view
Skip to first unread message

Vlamos

unread,
Oct 2, 2004, 7:21:25 AM10/2/04
to
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

Brusque

unread,
Oct 2, 2004, 12:34:28 PM10/2/04
to
> 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");


0 new messages