+ Reply to Thread
Results 1 to 9 of 9

Thread: Returning XML document from Web Service

  1. #1
    Administrator richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich's Avatar
    Join Date
    Mar 2008
    Location
    Somewhere only we know...
    Posts
    3,207
    Blog Entries
    14
    Real Name
    Rich
    Rep Power
    14

    Returning XML document from Web Service

    I have a web service that is used to retrieve a list of db entries based on the entry clicked by the user. This is all working fine. At the moment though I build a string of HTML code inside the web service and return this to my Javascript to render it to the screen.

    What I think might be better is to return an XML document to the Javascript and then handle the HTML rendering in there. But, I can't quite figure out how to return the result as an XML document. I think I need to use XMLTextWriter but I'm not sure how to write the XML to a variable and return that.

    At the moment I have:-
    Code:
    <WebMethod>_
        Public Function GetList(ByVal ref as integer) As ? what do I return it as? XMLDocument?
        Dim XMLresult as new XmlTextWriter( this would normally be a path to an XML file or response.OutputStream. What should I use as the stream?
    
    I think once I get the stream bit and what I should be returning the document as, I should be OK. It's these bits I'm unsure of.

    What I want returned is something like:-
    Code:
    <filenotelist>
       <filenote>
             <title>Filenote 1</title>
             <dateadded>25/03/09</dateadded>
             <note>Some text</note>
       </filenote>
       <filenote>
              <title>Filenote 2</title>
              <dateadded>24/03/09</dateadded>
              <note>Some more text</note>
       </filenote>
    </filenotelist>
    
    Or if an error occurs, something like:-
    Code:
    <filenotelist>
        <error>There was an error</error>
    </filenotelist>
    

  2. #2
    The Barnfather jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead's Avatar
    Join Date
    Mar 2008
    Location
    Reston, VA
    Posts
    4,547
    Blog Entries
    9
    Real Name
    Jason
    Rep Power
    22

    To be honest, I would just return the data as a DataTable and work with that.
    jmurrayhead
    If you agree, give me rep.
    If you like it here...throw us a few bones to help support us.


  3. #3
    Administrator richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich's Avatar
    Join Date
    Mar 2008
    Location
    Somewhere only we know...
    Posts
    3,207
    Blog Entries
    14
    Real Name
    Rich
    Rep Power
    14

    Would you use that in JS like an XML Doc?

  4. #4
    The Barnfather jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead's Avatar
    Join Date
    Mar 2008
    Location
    Reston, VA
    Posts
    4,547
    Blog Entries
    9
    Real Name
    Jason
    Rep Power
    22

    Perhaps I misunderstood your need...I suppose you could return a String or MemoryStream.
    jmurrayhead
    If you agree, give me rep.
    If you like it here...throw us a few bones to help support us.


  5. #5
    Developer Barnacle werD is on a distinguished road werD's Avatar
    Join Date
    Apr 2009
    Location
    Line 73 --^
    Posts
    13
    Rep Power
    3

    I would definitely just return the outerxml of the document as a string and parse it out of the xml response your getting from the web service. without namespaces xml is just delimeted text anyway. If you're not using full blown ajax(ie partial postbacks and what not), you can still use js, xsl, or css to transform and react to the returned string of xml data.

  6. #6
    Administrator richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich's Avatar
    Join Date
    Mar 2008
    Location
    Somewhere only we know...
    Posts
    3,207
    Blog Entries
    14
    Real Name
    Rich
    Rep Power
    14

    Not entirely sure what you mean by "return the outerxml of the document"?

    I am using AJAX to call the web service using a JS function which then returns to a completion JS function.

    I was just wondering if there was an easy way to build the XML document within the web service. I am working on something at the moment so hopefully that might do what I want...

  7. #7
    Developer Barnacle werD is on a distinguished road werD's Avatar
    Join Date
    Apr 2009
    Location
    Line 73 --^
    Posts
    13
    Rep Power
    3

    What i meant was that the XmlDocument class in .net has a property called OuterXml that is the entire string content of the document.


    So if you were constructing your document with code using the XmlDocument class
    ie
    Code:
    Dim xDoc as New XmlDocument
    'then something like this (on lunch)
    Dim rootNode as XmlElement = xDoc.CreateDocumentElement("MyElementName")
    
    you could just return xDoc.OuterXml

    of course you could always just do this

    Code:
    Dim returnStr as String = "<MyXmlDoc>" & _
    "<MyNode>"  & MyNodeValue & "</MyNode>" & _ 
      "</MyXmlDoc>"
    
    return returnStr
    
    Is that more clear?

  8. #8
    Administrator richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich is a splendid one to behold richyrich's Avatar
    Join Date
    Mar 2008
    Location
    Somewhere only we know...
    Posts
    3,207
    Blog Entries
    14
    Real Name
    Rich
    Rep Power
    14

    Ah, yes. That makes more sense.

    I am using the XMLDocument class, but was going to return an XML document. Should I set it to return a string and just return the OuterXML then?

  9. #9
    The Barnfather jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead has much to be proud of jmurrayhead's Avatar
    Join Date
    Mar 2008
    Location
    Reston, VA
    Posts
    4,547
    Blog Entries
    9
    Real Name
    Jason
    Rep Power
    22

    Quote Originally Posted by richyrich View Post
    Ah, yes. That makes more sense.

    I am using the XMLDocument class, but was going to return an XML document. Should I set it to return a string and just return the OuterXML then?
    Yes, RR, I think that's what he was suggesting from the start
    jmurrayhead
    If you agree, give me rep.
    If you like it here...throw us a few bones to help support us.


+ Reply to Thread

Similar Threads

  1. Returning a table in sp executed in an sp...
    By Lauramc in forum SQL Development
    Replies: 1
    Last Post: August 6th, 2008, 10:05 PM
  2. Accessing a Public Property in a web service
    By richyrich in forum .NET Development
    Replies: 0
    Last Post: May 23rd, 2008, 09:42 AM
  3. windows service send emails every 10 days
    By peebman2000 in forum .NET Development
    Replies: 8
    Last Post: May 20th, 2008, 05:00 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

SEO by vBSEO