Return XML Document

Discussion in 'ASP .Net' started by Anthony Bollinger, Jul 25, 2008.

  1. This is my first attempt at writing an XML web service.

    I have a query successfully written for SQL Server that returns XML data
    using FOR XML AUTO. It seems rather than processing the XML and building a
    text string in XML format to return, there should be some way to directly
    return the XML I get from SQL Server. What I seem to be getting is a
    properly formatted XML string that is not identified as XML (not sure why),
    but I want this to work pretty much like an RSS feed. I don't know how those
    are generated, but whatever requests them knows what to do with them. What I
    return should also be recognizable as an XML document. What is the best way
    to do this?

    Thanks!
    Tony
     
    Anthony Bollinger, Jul 25, 2008
    #1
    1. Advertising

  2. I do not have an answer right this second, as it has been awhile, but the
    answer is located in books online.

    By default, you get an XML snippet from the FOR XML features in SQL Server.
    There is either a flag that returns a proper root or an easy way to get it
    to return. Then you will have valid XML.

    If I get the chance, I will post, but take a look at the SQL books online
    FOR XML documentation and you should find the answer.

    --
    Gregory A. Beamer
    MVP, MCP: +I, SE, SD, DBA

    Subscribe to my blog
    http://gregorybeamer.spaces.live.com/lists/feed.rss

    or just read it:
    http://gregorybeamer.spaces.live.com/

    ********************************************
    | Think outside the box! |
    ********************************************
    "Anthony Bollinger" <> wrote in message
    news:%239C2%23$...
    > This is my first attempt at writing an XML web service.
    >
    > I have a query successfully written for SQL Server that returns XML data
    > using FOR XML AUTO. It seems rather than processing the XML and building a
    > text string in XML format to return, there should be some way to directly
    > return the XML I get from SQL Server. What I seem to be getting is a
    > properly formatted XML string that is not identified as XML (not sure
    > why), but I want this to work pretty much like an RSS feed. I don't know
    > how those are generated, but whatever requests them knows what to do with
    > them. What I return should also be recognizable as an XML document. What
    > is the best way to do this?
    >
    > Thanks!
    > Tony
     
    Cowboy \(Gregory A. Beamer\), Jul 26, 2008
    #2
    1. Advertising

  3. > properly formatted XML string that is not identified as XML (not sure
    > why), but I want this to work pretty much like an RSS feed. I don't know
    > how those



    I think the reason is that the XML string does not have a root.

    You can use:

    SELECT * FROM TableName FOR XML RAW('NameOfRootElement')


    HTH

    --
    Happy Hacking,
    Gaurav Vaish | http://dwt.sourceforge.net
    http://blogs.mastergaurav.com | http://eduzine.edujini-labs.com
    --------------------------------
     
    Gaurav Vaish \(a.k.a. MasterGaurav\), Jul 27, 2008
    #3
  4. > properly formatted XML string that is not identified as XML (not sure
    > why), but I want this to work pretty much like an RSS feed. I don't know
    > how those



    I think the reason is that the XML string does not have a root.

    You can use:

    SELECT * FROM TableName FOR XML RAW('NameOfRootElement')


    HTH

    --
    Happy Hacking,
    Gaurav Vaish | http://dwt.sourceforge.net
    http://blogs.mastergaurav.com | http://eduzine.edujini-labs.com
    --------------------------------
     
    Gaurav Vaish \(a.k.a. MasterGaurav\), Jul 27, 2008
    #4
  5. Thank you for your answer. I am not sure which SQL books online you mean.
    Could you post a URL or two?

    I do not think the issue I am having is proper XML, since I have that, but
    rather it is not identified on the receiving end as XML, even though the
    returned file is properly formatted. In fact, my first line is:

    <?xml version="1.0" encoding="utf-8" ?>

    And the remainder is a full XML document.

    Unfortunately, I must need to set something additional in the web service
    response, because consumers are not recognizing this as an XML file. Is
    there a way to set the type of the response? I think I have seen this.

    Many thanks! --Tony

    "Cowboy (Gregory A. Beamer)" <> wrote in
    message news:%...
    >I do not have an answer right this second, as it has been awhile, but the
    >answer is located in books online.
    >
    > By default, you get an XML snippet from the FOR XML features in SQL
    > Server. There is either a flag that returns a proper root or an easy way
    > to get it to return. Then you will have valid XML.
    >
    > If I get the chance, I will post, but take a look at the SQL books online
    > FOR XML documentation and you should find the answer.
    >
    > --
    > Gregory A. Beamer
    > MVP, MCP: +I, SE, SD, DBA
    >
    > Subscribe to my blog
    > http://gregorybeamer.spaces.live.com/lists/feed.rss
    >
    > or just read it:
    > http://gregorybeamer.spaces.live.com/
    >
    > ********************************************
    > | Think outside the box! |
    > ********************************************
    > "Anthony Bollinger" <> wrote in message
    > news:%239C2%23$...
    >> This is my first attempt at writing an XML web service.
    >>
    >> I have a query successfully written for SQL Server that returns XML data
    >> using FOR XML AUTO. It seems rather than processing the XML and building
    >> a text string in XML format to return, there should be some way to
    >> directly return the XML I get from SQL Server. What I seem to be getting
    >> is a properly formatted XML string that is not identified as XML (not
    >> sure why), but I want this to work pretty much like an RSS feed. I don't
    >> know how those are generated, but whatever requests them knows what to do
    >> with them. What I return should also be recognizable as an XML document.
    >> What is the best way to do this?
    >>
    >> Thanks!
    >> Tony

    >
     
    Anthony Bollinger, Jul 27, 2008
    #5
  6. re:
    !> I am not sure which SQL books online you mean.
    !> Could you post a URL or two?

    SQL Server Books Online...

    General info :
    http://msdn.microsoft.com/en-us/library/ms166018.aspx

    Download :
    http://www.microsoft.com/downloads/...5D-00DF-4220-B133-29C1E0B6585F&displaylang=en





    Juan T. Llibre, asp.net MVP
    asp.net faq : http://asp.net.do/faq/
    foros de asp.net, en espaƱol : http://asp.net.do/foros/
    ======================================
    "Anthony Bollinger" <> wrote in message news:uN9CVi$...
    > Thank you for your answer. I am not sure which SQL books online you mean. Could you post a URL or two?
    >
    > I do not think the issue I am having is proper XML, since I have that, but rather it is not identified on the
    > receiving end as XML, even though the returned file is properly formatted. In fact, my first line is:
    >
    > <?xml version="1.0" encoding="utf-8" ?>
    >
    > And the remainder is a full XML document.
    >
    > Unfortunately, I must need to set something additional in the web service response, because consumers are not
    > recognizing this as an XML file. Is there a way to set the type of the response? I think I have seen this.
    >
    > Many thanks! --Tony
    >
    > "Cowboy (Gregory A. Beamer)" <> wrote in message
    > news:%...
    >>I do not have an answer right this second, as it has been awhile, but the answer is located in books online.
    >>
    >> By default, you get an XML snippet from the FOR XML features in SQL Server. There is either a flag that returns a
    >> proper root or an easy way to get it to return. Then you will have valid XML.
    >>
    >> If I get the chance, I will post, but take a look at the SQL books online FOR XML documentation and you should find
    >> the answer.
    >>
    >> --
    >> Gregory A. Beamer
    >> MVP, MCP: +I, SE, SD, DBA
    >>
    >> Subscribe to my blog
    >> http://gregorybeamer.spaces.live.com/lists/feed.rss
    >>
    >> or just read it:
    >> http://gregorybeamer.spaces.live.com/
    >>
    >> ********************************************
    >> | Think outside the box! |
    >> ********************************************
    >> "Anthony Bollinger" <> wrote in message news:%239C2%23$...
    >>> This is my first attempt at writing an XML web service.
    >>>
    >>> I have a query successfully written for SQL Server that returns XML data using FOR XML AUTO. It seems rather than
    >>> processing the XML and building a text string in XML format to return, there should be some way to directly return
    >>> the XML I get from SQL Server. What I seem to be getting is a properly formatted XML string that is not identified
    >>> as XML (not sure why), but I want this to work pretty much like an RSS feed. I don't know how those are generated,
    >>> but whatever requests them knows what to do with them. What I return should also be recognizable as an XML document.
    >>> What is the best way to do this?
    >>>
    >>> Thanks!
    >>> Tony

    >>

    >
     
    Juan T. Llibre, Jul 27, 2008
    #6
  7. Thanks for that. Also, I think you are referring to the ROOT
    keyword/function which will generate a root node around your XML elements in
    query results returned from SQL 2005. --Joe
     
    Anthony Bollinger, Jul 27, 2008
    #7
  8. Yes, that is it. I assume you found the SQL books online file?

    --
    Gregory A. Beamer
    MVP, MCP: +I, SE, SD, DBA

    Subscribe to my blog
    http://gregorybeamer.spaces.live.com/lists/feed.rss

    or just read it:
    http://gregorybeamer.spaces.live.com/

    ********************************************
    | Think outside the box! |
    ********************************************
    "Anthony Bollinger" <> wrote in message
    news:...
    > Thanks for that. Also, I think you are referring to the ROOT
    > keyword/function which will generate a root node around your XML elements
    > in query results returned from SQL 2005. --Joe
     
    Cowboy \(Gregory A. Beamer\), Jul 29, 2008
    #8
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Tony Prichard
    Replies:
    0
    Views:
    755
    Tony Prichard
    Dec 12, 2003
  2. Manish Hatwalne
    Replies:
    1
    Views:
    406
    Martin Honnen
    Jul 13, 2004
  3. Replies:
    4
    Views:
    691
  4. Greenhorn
    Replies:
    15
    Views:
    849
    Keith Thompson
    Mar 6, 2005
  5. icogs
    Replies:
    0
    Views:
    149
    icogs
    Jan 31, 2008
Loading...

Share This Page