• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Parsing XML (jsp/struts/apache environment)

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Ranch Hand
Posts: 906
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
reply
    Bookmark Topic Watch Topic
  • New Topic