I am trying to generate an XML file using T-SQL with a default namespace in the root node but no namespaces defined in the child nodes.
DECLARE @xmlData XML
DECLARE @xmlInner XML
SELECT @xmlInner =
(
SELECT * FROM dbo.GH_DATA_BS_EVLTN_MNTH_ANL [r]
FOR XML PATH('r'), TYPE
)
;WITH XMLNAMESPACES (DEFAULT 'http://www.testnamespace.com')
SELECT @xmlData =
(
SELECT '2012-10-25T14:13:00Z' as "@DataFeedDate",@xmlInner
FOR XML PATH('root')
)
SELECT @xmlData
The script above generates the following XML file
<root xmlns="http://www.testnamespace.com" DataFeedDate="2012-10-25T14:13:00Z">
<r xmlns="">
<RPRT_DT_CD>2012-10-25T14:15:00-05:00</RPRT_DT_CD>
<RPRT_MO_CD>2013-01</RPRT_MO_CD>
<RPRT_EV_CD>1</RPRT_EV_CD>
</r>
</root>
The issue is that tag includes the blank namespace xmlns="" but the intended result is to get simply with no namespace defined.