I have a SQL Server table with an XML column like this:
create table tab
(
Id int,
Title nvarchar(200),
XmlCol xml
)
I need to return an XML like this
<tabs>
<tab Id="1" Title="Some Title">
<xmlcontent>...</xmlcontent>
<xmlcontent>...</xmlcontent>
<xmlcontent>...</xmlcontent>
</tab>
</tabs>
My best approach so far is:
select Id, Title, XmlCol.Query('xmlcontent')
from tab
for xml raw('tab'), root('tabs')
but I am getting this:
<tabs>
<tab Id="1" Title="Some Title">
<XmlCol>
<xmlcontent>...</xmlcontent>
<xmlcontent>...</xmlcontent>
<xmlcontent>...</xmlcontent>
<XmlCol>
</tab>
</tabs>
XmlCol column contains XML data like this (not well-formed)
<xmlcontent>...</xmlcontent>
<xmlcontent>...</xmlcontent>
<xmlcontent>...</xmlcontent>
Any idea how to flatten the structure to omit the XmlCol node?