SAX & Servlets - How

M

Michael Erangey

Hi all,

need some help on how to parse an xml file using SAX in a servlet.

I am completely lost on how to get it to work. I have no problem when it's a
stand alone command line program (there are enough examples out there) but
when I try to translate it to a servlet I lose it altogether.

I am trying to learn J2EE so any help would be appreciated. I just need some
sample code on how you parse using SAX in a servlet ie. Can I do it all in
one servlet, or for example on the Http Post do I call a generic servlet.

Appreciate any help.

Thanks,

Michael
 
J

Jose Rubio

Michael Erangey said:
Hi all,

need some help on how to parse an xml file using SAX in a servlet.

I am completely lost on how to get it to work. I have no problem when it's a
stand alone command line program (there are enough examples out there) but
when I try to translate it to a servlet I lose it altogether.
There's no reason why you need to do anything different if you're in a
servlet.

So if your command line does something like:

main( ... )
{
Parser.parseXml( file );
}

There's nothing impeding from doing

doPost( ... )
{
Parser.parseXml( file );
}

I am trying to learn J2EE so any help would be appreciated. I just need some
sample code on how you parse using SAX in a servlet ie. Can I do it all in
one servlet, or for example on the Http Post do I call a generic servlet.

If you are going to use this parsing code in other places, I'll suggest that
you keep it outside of the Servlet, and just invoke the parsing methods from
the servlet.
Appreciate any help.

Thanks,

Michael

Hope it helps

Jose Rubio
 
C

Chris Murphy

Jose is absolutely right. If you want a Servlet that can parse a file on
the server, it would be no different than your command line version.
But, it sounds like your question is more about how to get data uploaded
or "posted" to your Servlet to the parser. In that case you'd want to
learn about how HTTP and Servlets work. For example you could possibly
pass a "request" stream from the Servlet client directly to the parser,
or you could save off some XML that was "posted" to your Servlet to a
file on the server and parse that. There are tons of examples floating
around for "file upload Servlet" and such.

-Murphy
 

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

Similar Threads

SAX and Servlets - How? 0
servlets 2
Accessing Server File with Servlets 6
JSP, Servlets 9
Instantiating Servlets at runtime 5
Ugly SAX 5
accessing servlets using submit buttons 2
Servlets using NetBeans 4.1 0

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top