Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Formating and Displaying  XML data, in a JSP?

Posted on 2007-11-22
2
Medium Priority
?
619 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 270 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 26

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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

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…
When there is a disconnect between the intentions of their creator and the recipient, when algorithms go awry, they can have disastrous consequences.
The viewer will learn how to implement Singleton Design Pattern in Java.
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…
Suggested Courses

885 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