wood burning stoves 2.0*
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


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Web Services
Bookmark "Parsing XML (jsp/struts/apache environment)" Watch "Parsing XML (jsp/struts/apache environment)" New topic
Author

Parsing XML (jsp/struts/apache environment)

Geoff Garcia
Greenhorn

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>
<query>JJ</query>
<response>JJ1</response>
<response>JJ2</response>
<response>JJ3</response>
</queryAndResponse>
</queryAndResponseSet>
</xmlRouterResponse>

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.net.*;
import java.io.*;
import java.util.*;

public class webTest2Bean {
String theQuery;

public void setGuess(String guess) {
try{
String linky = "http://centraldictionaryservices.xxx.com:7000/cds/index.cds?alternativeTerms/term/term="+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
Greenhorn

Joined: Jul 10, 2003
Posts: 22
I found one page on the web that shows an example of what I'm looking to do:
http://www.geocities.com/paikiran/articles/xml1.html

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="http://www.epfwiki.net/wikis/openup/" target="_blank" rel="nofollow">Agile OpenUP</a> in the Eclipse community
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Parsing XML (jsp/struts/apache environment)
 
Similar Threads
HttpURLConnection
FileNotFoundException,(help please)
Why is Runtime.getRuntime().exec() not working in JSP?
Problem with HP UX ia64 while using Process proc = Runtime.getRuntime().exec( command );
Help! java.io.FileNotFoundException