• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to render XML over jsp  RSS feed

 
vivek dhiman
Ranch Hand
Posts: 155
Netbeans IDE Tomcat Server
  • Mark post as helpful
  • send pies
  • 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.

<cut 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]
 
Dave Tolls
Ranch Hand
Posts: 2839
30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What does your log show for final_str?
 
vivek dhiman
Ranch Hand
Posts: 155
Netbeans IDE Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

Now XML is rendering properly after using escapeXML = true in cut 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
Ranch Hand
Posts: 2839
30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I can't see any XML there.
 
Tim Holloway
Bartender
Posts: 18663
71
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • 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: 155
Netbeans IDE Tomcat Server
  • Mark post as helpful
  • send pies
  • 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]
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66158
146
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Continue to escape the output, and display it within <pre> tags to preserve formatting.
 
vivek dhiman
Ranch Hand
Posts: 155
Netbeans IDE Tomcat Server
  • Mark post as helpful
  • send pies
  • 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
Bartender
Posts: 18663
71
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • 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: 155
Netbeans IDE Tomcat Server
  • Mark post as helpful
  • send pies
  • 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.
 
paul nisset
Ranch Hand
Posts: 270
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you tried using XSLT to format it ?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66158
146
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!