Re: changing the results header with for xml
- From: Tristan <Tristan@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Tue, 5 May 2009 05:27:01 -0700
Martin's solution (thanks Martin!) can be adapted to give the XML declaration
as the first line in xml produced by a 'for xml' query:
e.g.
select (
select top 1 *
from tablename
for xml auto, elements xsinil, ROOT('myXml'))
as '<?xml version="1.0" encoding="utf-8"?>'
....gives:
<?xml version="1.0" encoding="utf-8"?>
<myXml xmlns:xsi="http://www.w3.org/2001/XMLSchema-Instance">
<OrderHeader>
<OrderHeaderID>37424</OrderHeaderID>
....
Thanks for the quick reply Martin.
Tristan
--
Managing knowledge is just as important as managing technology.
"Martin Honnen" wrote:
Tristan wrote:.
I'm getting results out of sql server 2005 as xml in the desired format
except the results header which is put before the xml. Any ideas how to
remove or modify the results header when returning data for xml? For example,
with the following query...
select top 1 *
from OrderHeader
WHERE limitprice is null
for xml auto, elements xsinil, ROOT('myorders')
...the xml returned (below) is headed with this row:
"XML_F52E2B61-18A1-11d1-B105-00805F49916B".
I can change column headings normally with sql results but how can it be
done for the single result column of a for xml query?
Try like this:
SELECT (SELECT TOP 1 *
FROM Orders
FOR XML AUTO, ROOT('ORDERS'), TYPE) AS XmlCol;
so for your query that should be
SELECT (select top 1 *
from OrderHeader
WHERE limitprice is null
for xml auto, elements xsinil, ROOT('myorders'), TYPE) AS XmlCol;
where 'XmlCol' is the column name you want to have.
--
Martin Honnen --- MVP XML
http://msmvps.com/blogs/martin_honnen/
- References:
- changing the results header with for xml
- From: Tristan
- Re: changing the results header with for xml
- From: Martin Honnen
- changing the results header with for xml
- Prev by Date: Re: changing the results header with for xml
- Next by Date: 12 Opinion de Dsiconsolas.com 64288
- Previous by thread: Re: changing the results header with for xml
- Next by thread: 12 Opinion de Dsiconsolas.com 64288
- Index(es):
Relevant Pages
|