• 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
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

How to show an xml content in a Jsp page?

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I use <jsp:include page=".....xml" /> tag in a jsp file to include an xml file. When this jsp page is open, only the text content in the xml file shows up with plain text. I want this xml file shows up like in IE (with xml format). Does anyone know how to do it? Thanks.
 
Greenhorn
Posts: 12
Tomcat Server Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I presume you just want the full content to display including the tags. If you want it to 'fold' like the IE display does (by clicking on the '-' signs) you need some serious JavaScript to include that functionality.

The problem you have is the jsp:include tag will insert the xml file as part of the HTML. The browser (which thinks it is rendering a HTML page) will look at the XML tags and ignore them as invalid, resulting in just the data between the tags being displayed as text.

I don't know what you are using behind the scenes, but if you are using struts, I would create an Action that accepts the XML filename as a parameter, and copy the file to the browser translating all '<' characters to the HTML entity '<' and all the '>' characters as '>'. I would then invoke that Action using AJAX so that it behaved like an inline tag such as <img>....
 
Matt W Robinson
Greenhorn
Posts: 12
Tomcat Server Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry - the previous post is confusing because the forum itself rendered the symbols in the text:
... browser translating all '<' characters to the HTML entity '<' and all the '>' characters as '>'. ...
Should read:
... browser translating all '<' characters to the HTML entity '&lt;' and all the '>' characters as '&gt;'

Got caught by my own explanation :-))
 
Sheriff
Posts: 67754
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
All of that is not necessary.

Use <c:import> to load the XML file into a scoped variable, and then use <c:out> to display it. The <c:out> will automatically convert the markup to HTML entities.
 
Chan Yan
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Bear Bibeault:
All of that is not necessary.

Use <c:import> to load the XML file into a scoped variable, and then use <c:out> to display it. The <c:out> will automatically convert the markup to HTML entities.



Thank you, Matt W Robinson & Bear Bibeault. I tried to use <c:import . It works. The page shows the content of the XML in plain text as a long string. I want to know if any good way to make it looks better, like each item shows on seperated line. Anyway, thank both of you very much.
 
Bear Bibeault
Sheriff
Posts: 67754
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
If you place the output within a <pre> element, it will preserve the formatting.
 
Matt W Robinson
Greenhorn
Posts: 12
Tomcat Server Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you are prepared to go to the lengths I suggested, you can do whatever you like to the XML code, such as colour code it, format it, etc. This is because your code has to do all work (open the file, read the contents, do translations) anyway.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic