Solved

Formating and Displaying  XML data, in a JSP?

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

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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

This algorithm (in C#) will resize any image down to a given size while maintaining the original aspect ratio. The maximum width and max height are both optional but if neither are given, the original image is returned. This example is designed t…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
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.

757 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now