Solved

Formating and Displaying  XML data, in a JSP?

Posted on 2007-11-22
2
610 Views
Last Modified: 2013-11-24
I am writing a web page wrapper for another website that gives results back from a search of Documents.
I am creating it using JSP & Servlets. I allow the user to enter in a Search word on the webpage and hit submit, this search word gets passed from the JSP to a Servlet. The servlet then adds this query to a url and hits another website to get back info.
It all works fine and the information that is returned is like...Author, Book Name etc.

But it comes back in a StringBuffer. The StringBuffer is just full of text and the text is in XML. I am not sure of what is the best way to seperate out the data so it can be displayed back neatly onto a JSP.
Not sure what the best way to parse this data is?

Can anyone help?
0
Comment
Question by:ShamD
2 Comments
 
LVL 4

Accepted Solution

by:
jcoombes earned 90 total points
ID: 20337849
You might want to transform the resultant XML using XSLT which can produce HTML (or whatever you want) which you can then embed/display within your JSP.

There are numerous examples of how to do this kind of stuff on web, here's one site that describes the basic process quite well:

http://www.informit.com/articles/article.aspx?p=26351&seqNum=7&rl=1

Given that you have your XML information in a StringBuffer, then you just need to change the bits that refer to a StreamSource so that you build the source based on the contents of the buffer.
/*
 * e.g.
 */
 
StreamSource src= new StreamSource(stringBuffer.toString());

Open in new window

0
 
LVL 25

Expert Comment

by:Tomas Helgi Johannsson
ID: 20463473
    Hi!

Here is several JSP XML examples to look at :
http://www.java2s.com/Code/Java/JSP/XML.htm
http://www.java2s.com/Code/Java/JSP/JSPXMLandXSLTtransform.htm

Regards,
   Tomas Helgi
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Spring Controller - inheritance in request parameter 3 60
What is JNDI datasource in spring 1 62
by zero exception 10 40
going to wrong jsp page 2 20
One of Google's most recent algorithm changes affecting local searches is entitled "The Pigeon Update." This update has dramatically enhanced search inquires for the keyword "Yelp." Google searches with the word "Yelp" included will now yield Yelp a…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question