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

read xml from a url in jsp

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Hi All,

How i can read a xml file from a url

example: http://eampl.ecom/text.xml

and show exact the whole xml body in jsp page?

I have tried jdom in jsp





but its only returning value. I need the full xml body with value. Can any one guide me please?

 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
How do you know it is returning "value"? If it were returning XML, you would be just copying the XML to the JSP's output. The browser would see the XML tags and, since they aren't HTML (isn't that right?) it would just ignore them. So the person looking at the browser wouldn't see them, even though they were successfully retrieved by your code.

Of course you could use the browser's "View Page Source" feature to see if that happened. Did you try that?
 
Mahfuzul islam
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
@Paul Clapham

Thanks! for your response.

As per your tips i have checked the "View source" and found there is the complete XML file. I think in jsp out.println is only showing the value ignoring the xml body. Right?

My plan as below:

*After read the XML store in a variable
*Parse XML on that variable
*get the value in required order to show.

Please let know any suggestion.


 
Paul Clapham
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator

Mahfuzul islam wrote:As per your tips i have checked the "View source" and found there is the complete XML file. I think in jsp out.println is only showing the value ignoring the xml body. Right?



No, that's not right. It can't be right because you yourself checked and found the whole XML file being displayed by the browser. And what you see in the browser's source is what the JSP outputs, nothing more or less. So it's like I said, the browser is handling your XML in a way you don't like.

So what you need to do is to escape the XML, so the browser treats it as text instead of markup.

Which brings us to another important point. Java code like this has no place in a JSP. It should be put in a servlet, or some other Java class, and then the servlet should put the desired data into request scope before forwarding to the JSP whose job is only to generate the output. And in that JSP you should use the EL (expression language) to handle data forwarded in request scope from the servlet. As it happens the <c:out> element will automatically escape XML, which is exactly what you want.

Your alternative would be to write your own code to process that string and escape the XML it contains. But why would you want to do that when the code you should be using will do it for you automatically?
 
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:
  • Report post to moderator
We've already been over this ground in the other post on this same topic. I'm closing this one. Please do not post the same issue more than once.
 
She said she got a brazillian. I think owning people is wrong. That is how I learned ... tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
    Bookmark Topic Watch Topic
  • New Topic