File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Web Services and the fly likes Parsing XML (jsp/struts/apache environment) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Web Services
Bookmark "Parsing XML (jsp/struts/apache environment)" Watch "Parsing XML (jsp/struts/apache environment)" New topic

Parsing XML (jsp/struts/apache environment)

Geoff Garcia

Joined: Jul 10, 2003
Posts: 22
I am integrating with a webservice in my jsp code.

I built a little class file that gets the results and outputs them to the jsp page.
Unfortunately the output is in XML format and looks like this:

- <xmlRouterResponse>
- <queryAndResponseSet>
- <queryAndResponse>

My question is, how can I extract just the response data?
Obviously this requires an XML parser, which I assume is incorporated in Apache?
I've tried hunting google and looking through books, but all the examples I've seen are super duper in depth and don't spend any time or show any examples on how something this simple would be done.

Can this be done from the JSP code? or is this something that is done from within the class/java file?

Any specific help would be fantastic!

My current Java file looks like this:
package webTest2;
import java.util.*;

public class webTest2Bean {
String theQuery;

public void setGuess(String guess) {
String linky = ""+guess;
URL u = new URL(linky);
InputStream is = u.openStream();
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
theQuery = br.readLine();
catch (MalformedURLException ex){
System.err.println("catch 1 "+ex);
catch(IOException ex){
System.err.println("catch 2 "+ex);

public String getHint() {
return theQuery;
Geoff Garcia

Joined: Jul 10, 2003
Posts: 22
I found one page on the web that shows an example of what I'm looking to do:

The code says to use these imports:
import org.w3c.dom.Document;
import org.w3c.dom.*;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.DocumentBuilder;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;

However when I add this to the top of my java file it complains that the package doesn't exist, where can I get them from?
(assuming this is even the solution!)

I'm using jdk1.3.1_07

I tried to do the wildcard and just add
import org.w3c.dom.*;
import javax.xml.parsers.*;
import org.xml.sax.*;

and it says I'm missing all of them.

I'm aware just how basic this question is, but I gotta start somewhere!
[ August 11, 2004: Message edited by: Geoff Garcia ]
JeanLouis Marechaux
Ranch Hand

Joined: Nov 12, 2001
Posts: 906
import org.w3c.dom.*;
import javax.xml.parsers.*;
import org.xml.sax.*;

.... are all included in J2EE 1.3
So, maybe the J2EE.jar is not in your classpath, or maybe you are trying to find them from the J2SE. Only the J2EE contains them

/ JeanLouis<br /><i>"software development has been, is, and will remain fundamentally hard" (Grady Booch)</i><br /> <br />Take a look at <a href="" target="_blank" rel="nofollow">Agile OpenUP</a> in the Eclipse community
I agree. Here's the link:
subject: Parsing XML (jsp/struts/apache environment)
It's not a secret anymore!