Re: Retrieving and Combining XML
- From: "Michael Rys [MSFT]" <mrys@xxxxxxxxxxxxxxxxxxxx>
- Date: Sat, 29 Oct 2005 13:52:58 -0700
In SQL Server 2005, you can use ROOT('myRoot') in the FOR XML clause.
In SQL Server 2000, your workaround works. Alternatively, there is a root
property on your connection that you can set in ADO, OLEDB, ADO.Net to get
the root element added on the client.
Best regards
Michael
"gilly3" <news@xxxxxxxxxxxxxxxx> wrote in message
news:Xns96FCA5F95596AnewsNOSPAMgilly3com@xxxxxxxxxxxxxxxx
> "Michael Rys [MSFT]" <mrys@xxxxxxxxxxxxxxxxxxxx> wrote in
> news:uZgb5Zq2FHA.3880@xxxxxxxxxxxxxxxxxxxx:
>
>> FOR XML EXPLICIT was a good try. But you will need the !xml directive
> in
>> your column alias.
>>
>> Eg,
>>
>> select .... , xmlData as "element!1!row!xml" .... FOR XML EXPLICIT.
>>
>> Best regards
>> Michael
>
> Thanks, that fixes my formatting problem, but I still had trouble
> getting each record under a common root node.
>
> My sql looked like this:
>
> select
> 1 tag,
> null parent,
> [xmlData] [xRoot!1!xElement!xml]
> from xmlTable
> for xml explicit
>
> this gave each record two parent nodes like this with no common root
> node:
>
> <xRoot>
> <xElement>
> <foo>
> ...
> </foo>
> </xElement>
> </xRoot>
> <xRoot>
> <xElement>
> <foo>
> ...
> </foo>
> </xElement>
> </xRoot>
>
> I want one parent node, and for that node to be the root of all the
> records. I managed to make it work by adding a parent node in my
> select, and eliminating extra nodes by using !xmltext, instead of !xml
> like this:
>
>
> select
> 1 tag,
> null parent,
> null [xRoot!1!!xmltext],
> null [foo!2!!xmltext]
> union all
> select 2,
> 1,
> null,
> [xmlData]
> from xmlTable
> for xml explicit
>
> This works, but it seems like a bit of a hack. Is there a more elegant
> solution? If not, I'll just be happy this works as well as it does.
>
> thanks
>
> -ivan.
.
- References:
- Retrieving and Combining XML
- From: gilly3
- Re: Retrieving and Combining XML
- From: Michael Rys [MSFT]
- Re: Retrieving and Combining XML
- From: gilly3
- Retrieving and Combining XML
- Prev by Date: Re: SQLXML for xml explicit
- Next by Date: Re: Retrieve and write
- Previous by thread: Re: Retrieving and Combining XML
- Next by thread: Re: element centric XML --- for XML explicit - suggestion needed
- Index(es):
Relevant Pages
|