Good morning,
I have a big query using FOR XML PATH to output an XML file. I have a basic choice that basically just represents the root, i.e.
select * from tbl for xml path ('root'),elements xsinil
Then I have the following nested selections in this main selection ie
select ( select null [level1], '2' [level2] from tbl for xml path('nested1'),type ), ( select null [level1], '2' [level2] from tbl for xml path('nested2'),type ) for xml path('root'),elements xsinil
However, the argument of the xsinil element placed in the for xml path does not affect the contained subqueries, that is, the Level1 element is only a private tag. I need this to display as xsi: nil = "true".
I can achieve this by adding xsinil arguments to the xsinil argument, for example:
for xml path('nested1'),type,elements xsinil
The problem is that the namespace declaration is repeated at the subquery level.
I can find many examples of using xsinil elements, but not where it should apply to a subquery without re-declaring namesapce.
To confirm, I am looking for the following output:
<root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <nested1> <level1 xsi:nil="true"> <level2>2</level2> </nested1> <nested2> <level1 xsi:nil="true"> <level2>2</level2> </nested2> </root>
Hope you can help!