aspose file tools*
The moose likes Web Services and the fly likes How to display a xml in browser after inoke soap? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Web Services
Bookmark "How to display a xml in browser after inoke soap?" Watch "How to display a xml in browser after inoke soap?" New topic
Author

How to display a xml in browser after inoke soap?

lyo Yashnoo
Ranch Hand

Joined: Sep 15, 2003
Posts: 50
HI everyone:

I am a new developer in webservice soap. I come across a problem.
I want to invoke a soap method which return a List for example:

Now I want to display them in client's browser. What client will see in browser is :

But I don't know how to send the List to client and display them. Could I use Inputstream to do this?
Must I create xml document in server and send it to clients? I expect that I can do this using Stream.
Anyone can tell me how to send the data using Stream.
Thks!
Balaji Loganathan
author and deputy
Bartender

Joined: Jul 13, 2001
Posts: 3150
Originally posted by lyo Yashnoo:

Must I create xml document in server and send it to clients? I expect that I can do this using Stream.
Anyone can tell me how to send the data using Stream.
Thks!

Yes!
A simple servlet or jsp to convert the list in to xml document structure on the fly. it is important to set the page context and/or response header to text/xml
response.setContentType("text/xml");
response.setHeader("Content-Disposition","inline;filename=viewXML.xml ");
if not you can always show them as a table in HTML.


Spritle Software Blogs
lyo Yashnoo
Ranch Hand

Joined: Sep 15, 2003
Posts: 50
Thank you for your fast reply.
I know your means. It need set the document header. But I think the main problem is that how to write all the data to a Stream? And send the xml stream to clients? Should I use inputstream or pipestream?
Balaji Loganathan
author and deputy
Bartender

Joined: Jul 13, 2001
Posts: 3150
Originally posted by lyo Yashnoo:
Thank you for your fast reply.
I know your means. It need set the document header. But I think the main problem is that how to write all the data to a Stream? And send the xml stream to clients? Should I use inputstream or pipestream?

if i understood your problem correctly..
then all you need to do is..
  • A servlet to act as a webservice client
  • Invoke the webservice
  • Read the response
  • convert the list in to XML and show them in the webbroswer

  • You will be using PrintStream from servlet, so you don't have to worry abt other streams.
    lyo Yashnoo
    Ranch Hand

    Joined: Sep 15, 2003
    Posts: 50
    Hi
    I do this in this way but it don't work property. I use it in a servlet.When I click the hyperlink.it redirect a page ,error is:"the root of this document is not valid,error happen when process http://localhost:5050/lyoweb/getxml range1.
    my code is:

    what's wrong with it?
    Why it can't disply xml in browser?
    lyo Yashnoo
    Ranch Hand

    Joined: Sep 15, 2003
    Posts: 50
    If I use the System.out.println(doc). It will print

    Why it don't print the xml to Browser? :roll:
    Lasse Koskela
    author
    Sheriff

    Joined: Jan 23, 2002
    Posts: 11962
        
        5
    Take a look at this. (instead of a File, you'd create the StreamResult from the ServletOutputStream)


    Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
    Yashnoo lyo
    Ranch Hand

    Joined: Feb 17, 2003
    Posts: 152
    Thank you for your reply.
    I have seen your article.But it is not what I want. I mean I don't want to create a xml in the server.You know there will be many many file created if I use your method. So I want to write the Document to a Stream and send the XML Stream to client 's Browser. But I don't know how to do it
    It is possible?


    When I face C# and Java I choose Java.
    Balaji Loganathan
    author and deputy
    Bartender

    Joined: Jul 13, 2001
    Posts: 3150
    Originally posted by Yashnoo lyo:

    I mean I don't want to create a xml in the server.You know there will be many many file created if I use your method.

    You got to be missing Lasse point.. read again his reply..
    Lasse psoted:(instead of a File, you'd create the StreamResult from the ServletOutputStream)
    here is the sample code
    Yashnoo lyo
    Ranch Hand

    Joined: Feb 17, 2003
    Posts: 152
    Thanks!
    I find what I what to get . See here
    http://www.soapclient.com/SoapData.html
    I want to do that!
    You say I should use XMLWiki but I search this site find nothing .
    If I convert the xml to string, response should be set text/html other than text/xml. But I want to read the xml using Javascript in client. So I muse set the response to "text/xml".
    My javascript is simple this:

    The BiLoader is like a XMLDocument load a uri or url.The uri or url must is a xml file.So I expect set the response to "text/xml".
    It is possible to do this http://www.soapclient.com/SoapData.html ?
    Lasse Koskela
    author
    Sheriff

    Joined: Jan 23, 2002
    Posts: 11962
        
        5
    When you say "SOAP method returns a list", do you mean java.util.List or something else? If you already have a org.w3c.dom.Document representing the list, you can use this technique for writing the DOM object as raw XML using a servlet. If you have a java.util.List, for example, you can print out the XML by hand:

    [ January 30, 2004: Message edited by: Lasse Koskela ]
    Yashnoo lyo
    Ranch Hand

    Joined: Feb 17, 2003
    Posts: 152
    Thks . The second method is property to me. I will use it. Because I don't want to generate many xml file when client access my site.So I don't expect it will generate a xml on the server when I run the jsp. Is there any useful method convert a Document to String? Now I have a Document object I must convert it to String If I want to display them. I means is there any convinent method to do this?
    More :
    What the "on the fly" mean? Thks
    Lasse Koskela
    author
    Sheriff

    Joined: Jan 23, 2002
    Posts: 11962
        
        5
    Originally posted by Yashnoo lyo:
    Is there any useful method convert a Document to String?

    See DocumentToString in our Wiki.
    Originally posted by Yashnoo lyo:
    What the "on the fly" mean?
    It's a saying that, in our profession's context, is used to refer to doing something dynamically instead of statically.
    For example, in order to get the current time displayed using a nice graphic on a web page, we can either:
    a) generate one static .gif image file for every minute/second/whatever between 00:00-23:59, or
    b) generate a .gif image dynamically based on the current system time.
    Option B would be what "on the fly" means.
    Yashnoo lyo
    Ranch Hand

    Joined: Feb 17, 2003
    Posts: 152
    Thanks! Document can't be dislayed before it is converted to String.Yes.I will try it.
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: How to display a xml in browser after inoke soap?