2

I am trying to show a string containing xml data in xml format, on a jsp page. I do not want to parse the xml but just want to show on the browser xml data.

Would someone be able to help me out with this?

learner2010
  • 4,157
  • 5
  • 43
  • 68

2 Answers2

5
 <pre>
   <c:out value="${xmlString}" />
 </pre>

This will pretty print the xml

Sunil
  • 1,238
  • 3
  • 13
  • 21
  • In my case it just prints only XML tag values. It doe not print tags. Why so ? Any more setting needed ? – Kaushik Lele Jul 30 '15 at 06:23
  • I realized that is not being recognized. So I added <%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> After adding it (and adding supporting jar jstl-1.2.jar) it worked. Thanks. – Kaushik Lele Jul 30 '15 at 06:36
3
<c:out value="${theXmlString}"/>

If you want to preserve line breaks, use a pre tag:

<pre><c:out value="${theXmlString}"/></pre>
JB Nizet
  • 678,734
  • 91
  • 1,224
  • 1,255
  • thank you.. but it does not seem to print out the xml in xml format.. it just prints it out as one single string.. – learner2010 May 02 '12 at 18:49
  • It prints it as it is in the XML string. Do you mean you would like to indent the XML string? See http://stackoverflow.com/questions/139076/how-to-pretty-print-xml-from-java – JB Nizet May 02 '12 at 18:52