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

Re: Return XML Document by Cowboy

Cowboy
Fri Jul 25 21:58:55 CDT 2008

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" <tonyb@noemail.noemail> wrote in message
news:%239C2%23$n7IHA.616@TK2MSFTNGP02.phx.gbl...
> 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


Re: Return XML Document by Gaurav

Gaurav
Sun Jul 27 02:31:49 CDT 2008

> 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
--------------------------------





Re: Return XML Document by Gaurav

Gaurav
Sun Jul 27 02:31:49 CDT 2008

> 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
--------------------------------





Re: Return XML Document by Anthony

Anthony
Sun Jul 27 09:53:33 CDT 2008

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)" <NoSpamMgbworld@comcast.netNoSpamM> wrote in
message news:%23OftPus7IHA.3384@TK2MSFTNGP04.phx.gbl...
>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" <tonyb@noemail.noemail> wrote in message
> news:%239C2%23$n7IHA.616@TK2MSFTNGP02.phx.gbl...
>> 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
>


Re: Return XML Document by Mark

Mark
Sun Jul 27 10:13:00 CDT 2008

"Anthony Bollinger" <tonyb@noemail.noemail> wrote in message
news:uN9CVi$7IHA.1468@TK2MSFTNGP05.phx.gbl...

>> the answer is located in books online.
>>
>> take a look at the SQL books online
>
> Thank you for your answer. I am not sure which SQL books online you mean.

Gregory is referring to SQL Server Books Online - an electronic helpfile
installed (optionally) when you install SQL Server 2005. If you installed
it, you'll find the link in Start, Programs, SQL Server 2005, Documentation
and Tutorials.


--
Mark Rae
ASP.NET MVP
http://www.markrae.net


Re: Return XML Document by Juan

Juan
Sun Jul 27 12:03:52 CDT 2008

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/details.aspx?FamilyId=BE6A2C5D-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" <tonyb@noemail.noemail> wrote in message news:uN9CVi$7IHA.1468@TK2MSFTNGP05.phx.gbl...
> 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)" <NoSpamMgbworld@comcast.netNoSpamM> wrote in message
> news:%23OftPus7IHA.3384@TK2MSFTNGP04.phx.gbl...
>>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" <tonyb@noemail.noemail> wrote in message news:%239C2%23$n7IHA.616@TK2MSFTNGP02.phx.gbl...
>>> 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
>>
>



Re: Return XML Document by Anthony

Anthony
Sun Jul 27 12:45:40 CDT 2008

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


Re: Return XML Document by Cowboy

Cowboy
Tue Jul 29 09:28:41 CDT 2008

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" <tonyb@noemail.noemail> wrote in message
news:uVQngCB8IHA.3384@TK2MSFTNGP04.phx.gbl...
> 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