Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Servlets and XML

Status
Not open for further replies.
Aug 30, 2004
12
0
0
CA
I would like to create a servlet, which when accessed, will retrieve an
XML file, remotely over the Internet, and parse it to the browser's
screen.

Can anyone point to example code that will help me along?

Thanks.
 
A bit generic for me.

Could you tell us what do you hava so far?

Cheers,
Dian
 
Hi:

At the moment I am on the research stage - I have a Java console application running, that uses DOM, to parse an XML file to the console window.

I would like to use SAX and have the XML parsing incorporated into a servlet. I was wondering if there are any example code of doing this out in the Internet world.

Thanks for your help :)
 
If the XML file already exists, just set the content type :

response.setContentType("text/xml");

then load the file into a byte[] using a File and FileInputStream objects, and write it out :

OutputStream os = response.getOutputStream();
os.write(data);
os.flush();


If you are processing/generating an XML file on the fly using DOM or SAX, then just set the output stream to your servlet's output stream.

--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top