Hi

I am not much experienced in JSP.

I am facing one problem while printing a XML String on the screen.

Code snippet ->

String result = ab.returnResult();

result is returning a XML String..Suppose <A>123</A><B>SIR</B><C>21</C>

I am printing -> <tr><td><%= result %></td></tr>

I am getting 123SIR21 as output in the screen..

I want it as -> <A>123</A><B>SIR</B><C>21</C> ( with XML tags )..


Could anyone help me out of this issue...
I am sorry If I am asking a silly question..Please answer as early as possible..

You need to escape the XML strings returned and convert the <, > and other characters which have special meaning in HTML to their HTML entities.

< - &lt;
> - &gt;
" - &quot;

You can try something like:

String str = ab.result();
str = str.replaceAll("<", "&lt;").replaceAll(">", "&gt;");

thanks ~S.O.S~ for ur help...It worked..

Happy to help. :-)

any way to make the browser to present the string with the xml tags as real XML (i mean with the ability to click on the "+" and the "-", cause all it shows is a static string... and not xml...

?

No, there isn't any direct method of doing the same. This is because the representation you are talking about is the way browser is configured to / coded to display XML; this would differ from browser to browser.

If you want to make this happen, you would have to create a XML document instance from the XML received as string and apply some Javascript magic to convert that in memory tree structure to something of value for the client using a bunch of <ul> and <li> and what not. This is by no means a simple task unless you are well versed in Javascript.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.