Example: Specifying XSINIL with the ELEMENTS Directive
The following query specifies the
directive to generate element-centric XML from the
query result.
This is the partial result.
XML
Because the
column has null values for some products, the resulting XML won’t
generate the corresponding
element. By adding the
directive with
,
you can generate the
element even for NULL color values in the result set.
ELEMENTS
Color
<Color>
XSINIL
ELEMENTS
<Color>
USE
AdventureWorks2022;
GO
SELECT
ProductID,
Name
, Color
FROM
Production.Product
FOR
XML
RAW
, ELEMENTS;
GO
<row>
<ProductID>
1
</ProductID>
<Name>
Adjustable Race
</Name>
</row>.
<row>
<ProductID>
317
</ProductID>
<Name>
LL Crankarm
</Name>
<Color>
Black
</Color>
</row>
USE
AdventureWorks2022;
GO
SELECT
ProductID,
Name
, Color