Aracılığıyla paylaş


ÖRNEK: ELEMENT yönergesini ve varlık kodlama belirtme

Bu örnek arasındaki farkı gösterir Öğe and XML yönergeleri.The ELEMENT directive entitizes the data, but the XML directive does not.The <Summary> element is assigned XML, <Summary>This is summary description</Summary>, in the query.

Bu sorgu için göz önünde bulundurun:

SELECT  1 as Tag,
        0 as Parent,
        ProductModelID  as [ProductModel!1!ProdModelID],
        Name            as [ProductModel!1!Name],
        NULL            as [Summary!2!SummaryDescription!ELEMENT]
FROM    Production.ProductModel
WHERE   ProductModelID=19
UNION ALL
SELECT  2 as Tag,
        1 as Parent,
        ProductModelID,
        NULL,
       '<Summary>This is summary description</Summary>'
FROM   Production.ProductModel
WHERE  ProductModelID=19
FOR XML EXPLICIT

Bu kaynaklanır.Özet açıklaması sonucu entitized.

<ProductModel ProdModelID="19" Name="Mountain-100">
  <Summary>
    <SummaryDescription>&lt;Summary&gt;This is summary description&lt;/Summary&gt;</SummaryDescription>
  </Summary>
</ProductModel>

Şimdi belirtirseniz, XML sütun adı, yönergesindeSummary!2!SummaryDescription!XML, yerine Öğe emrini entitization olmadan Özet açıklamasını alır.

<ProductModel ProdModelID="19" Name="Mountain-100">
  <Summary>
    <SummaryDescription>
      <Summary>This is summary description</Summary>
    </SummaryDescription>
  </Summary>
</ProductModel>

Statik bir XML değeri atamak yerine, aşağıdaki sorgu kullandığı Query() yöntemXML CatalogDescription sütundan ürün modeli Özet açıklamasını almak türünüXML türü.Sonuç olması bilindiğinden XML türü, hiçbir entitization uygulanır.

SELECT  1 as Tag,
        0 as Parent,
        ProductModelID  as [ProductModel!1!ProdModelID],
        Name            as [ProductModel!1!Name],
        NULL            as [Summary!2!SummaryDescription]
FROM    Production.ProductModel
WHERE   CatalogDescription is not null
UNION ALL
SELECT  2 as Tag,
        1 as Parent,
        ProductModelID,
        Name,
       (SELECT CatalogDescription.query('
            declare namespace pd="https://schemas.microsoft.com/sqlserver/2004/07/adventure-works/ProductModelDescription";
          /pd:ProductDescription/pd:Summary'))
FROM     Production.ProductModel
WHERE    CatalogDescription is not null
ORDER BY [ProductModel!1!ProdModelID],Tag
FOR XML EXPLICIT

See Also

Reference