Bookmark Topic Watch Topic
  • New Topic

read xml from a url in jsp

 
Mahfuzul islam
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • 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?

 
Paul Clapham
Sheriff
Posts: 21882
36
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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
  • 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
Sheriff
Posts: 21882
36
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • 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?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65524
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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.
 
    Bookmark Topic Watch Topic
  • New Topic
Boost this thread!