• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to render XML over jsp

 
Ranch Hand
Posts: 157
Netbeans IDE Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have custom tag in which I am getting the content of XML files and storing them in Strings and trying to render on jsp. Below is some code snapshot.



What i use on jsp.

<c:out value = "${sitemap}" />

Attached is the image what i am getting on web page. This is string not XML and I am looking for XML
img2.png
[Thumbnail for img2.png]
 
Rancher
Posts: 4801
50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What does your log show for final_str?
 
vivek dhiman
Ranch Hand
Posts: 157
Netbeans IDE Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

Now XML is rendering properly after using escapeXML = true in c:out tag. But can you tell me how the indentation can apply on this XML. Attached is the image what i see?

Thanks

img3.png
[Thumbnail for img3.png]
 
Dave Tolls
Rancher
Posts: 4801
50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I can't see any XML there.
 
Saloon Keeper
Posts: 27752
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
XML resembles HTML, so when you send HTML to a browser, it may render the XML like it's HTML. Which means that any "html" tags that it doesn't understand will be ignored.

There are a couple of things you can do to avoid this. One is to be sure to incude the "<? xml >" processing instruction as the very first line of the output. Even more importantly, set the content-type header to "text/xml" so that the browser will know it's not supposed to be plain text or HTML. Many clients can also apply formatting to XML, but that's getting into a more esoteric area.

This was a JSP question, so I'm moving it to the JSP forum where you'll find more people who are expert on such things. JSP does XML quite well when you know how to do it, though.
 
vivek dhiman
Ranch Hand
Posts: 157
Netbeans IDE Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oh Sorry, Attached is what is output. I also want indentation on it. Thanks
img1.png
[Thumbnail for img1.png]
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Continue to escape the output, and display it within <pre> tags to preserve formatting.
 
vivek dhiman
Ranch Hand
Posts: 157
Netbeans IDE Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:Continue to escape the output, and display it within <pre> tags to preserve formatting.



Hi,

In that case XML displays, but in single line only no indentation. As attached
img1.png
[Thumbnail for img1.png]
 
Tim Holloway
Saloon Keeper
Posts: 27752
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Again, that has to do with how your contents are being displayed.

If you output the XML as text/text or on a text/html page, you will not get "pretty-printed" XML unless you personally inserted spaces and newline characters in the XML output. And in the case of HTML, the HTML formatter will remove most of the spaces and all of the newline characters as part of the display process.

If your content-type is set to text/xml, then the browser will use its XML MIME rendering processes and, depending on what version of what browser you are using, the displayed output might render with newlines and spaces and may even allow expanding/collapsing elements. Note that in such a case, a "save as" of the XML will NOT have pretty-printing beyond whatever manual formatting you've done, since the renderer is not the same thing as the contents being rendered.
 
vivek dhiman
Ranch Hand
Posts: 157
Netbeans IDE Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I have used <%@page contentType="text/xml" %> inside jsp. But no luck, Do you have any idea of plugin that is simple to use & can do formatting of this xml.
 
Ranch Hand
Posts: 572
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have you tried using XSLT to format it ?
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is the XML embedded inside other HTML, or is the whole page XML? If the former, you do not want to dick around with the content type. You'll either need to pretty-format the XML in advance, or find a JavaScript widget that'll display pretty XML for you.
 
reply
    Bookmark Topic Watch Topic
  • New Topic