I'm generating an XML document using FOR XML EXPLICIT
:
declare @MyTable table (value xml);
insert into @MyTable values
('<foo bar="data1">content1</foo>')
,('<foo bar="data2">content2</foo>')
,('<foo bar="data3">content3</foo>');
select 1 as Tag, null as Parent
, value as [x!1!!xml]
from @MyTable
for xml explicit;
And get such a response:
<x>
<foo bar="data1" xmlns="">content1</foo>
</x>
<x>
<foo bar="data2" xmlns="">content2</foo>
</x>
<x>
<foo bar="data3" xmlns="">content3</foo>
</x>
The problem is that I don't need the xmlns
attribute.
I found a solution, but it seems to be a kludge.
select 1 as Tag, null as Parent
, cast (value as varchar(200)) as [x!1!!xml]
from @MyTable
for xml explicit;
Is there a more elegant way to solve the problem?
Do not offer using FOR XML PATH/RAW/AUTO
.
EXPLICIT
mode is must.