Solved

Formating and Displaying  XML data, in a JSP?

Posted on 2007-11-22
2
611 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

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Dice Roll Probabilities 3 111
eclipse package explorer vs project explorer view 2 185
Eclipse with gitlab 1 81
hibernate insert example 13 34
Article by: Nadia
Suppose you use Uber application as a rider and you request a ride to go from one place to another. Your driver just arrived at the parking lot of your place. The only thing you know about the ride is the license plate number. How do you find your U…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
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…

820 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