예제: ELEMENTXSINIL 지시어 지정Example: Specifying the ELEMENTXSINIL Directive

요소 중심 XML을 검색하기 위해 ELEMENT 지시어를 지정할 때 열에 NULL 값이 있으면 EXPLICIT 모드에서 해당 요소가 생성되지 않습니다.When you specify the ELEMENT directive to retrieve element-centric XML, if the column has a NULL value, the corresponding element is not generated by the EXPLICIT mode. xsi:nil 특성이 TRUE 값으로 설정된 경우 NULL 값에 대한 요소를 생성하도록 요청하기 위해 선택적으로 ELEMENTXSINIL 지시어를 지정할 수 있습니다.You can optionally specify the ELEMENTXSINIL directive to request the generating element for NULL values where the xsi:nil attribute is set with the value TRUE.

다음 쿼리는 직원 주소가 포함된 XML을 생성합니다.The following query constructs XML that includes an employee address. AddressLine2City 열에서 열 이름은 ELEMENTXSINIL 지시어를 지정합니다.For AddressLine2 and City columns, the column names specify the ELEMENTXSINIL directive. 이렇게 하면 행 집합에서 AddressLine2City 열에 있는 NULL 값에 대한 요소가 생성됩니다.This generates the element for NULL values in the AddressLine2 and City columns in the rowset.

USE AdventureWorks2012;  
GO  
SELECT 1    as Tag,  
       NULL as Parent,  
       E.BusinessEntityID  as [Employee!1!EmpID],  
       BEA.AddressID as [Employee!1!AddressID],  
       NULL        as [Address!2!AddressID],  
       NULL        as [Address!2!AddressLine1!ELEMENT],  
       NULL        as [Address!2!AddressLine2!ELEMENTXSINIL],  
       NULL        as [Address!2!City!ELEMENTXSINIL]  
FROM   HumanResources.Employee AS E  
INNER JOIN Person.BusinessEntityAddress AS BEA  
    ON E.BusinessEntityID = BEA.BusinessEntityID  

UNION ALL  
SELECT 2 as Tag,  
       1 as Parent,  
       E.BusinessEntityID,  
       BEA.AddressID,  
       A.AddressID,  
       AddressLine1,   
       AddressLine2,  
       City   
FROM   HumanResources.Employee AS E  
INNER JOIN Person.BusinessEntityAddress AS BEA  
    ON E.BusinessEntityID = BEA.BusinessEntityID  
INNER JOIN Person.Address AS A  
    ON BEA.AddressID = A.AddressID  
ORDER BY [Employee!1!EmpID],[Address!2!AddressID]  
FOR XML EXPLICIT;  

다음은 결과의 일부입니다.This is the partial result:

<Employee xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

EmpID="1" AddressID="249">

<Address AddressID="249">

<AddressLine1>4350 Minute Dr.</AddressLine1>

<AddressLine2 xsi:nil="true" />

<City>Minneapolis</City>

</Address>

</Employee>

...

참고 항목See Also

FOR XML에서 EXPLICIT 모드 사용Use EXPLICIT Mode with FOR XML