XML声明到FOR XML EXPLICIT

时间:2013-04-16 13:09:23

标签: sql-server xml declaration for-xml-explicit

我正在使用SQL Server 2008并将SQL查询的输出写入XML。生成XML但无法添加声明

<xml version "1.0" encoding = "UTF-8">

尝试添加

select <xml version "1.0"..> 
union all (select) 

但这不起作用。我需要使用CDATA,因为我在EMP_MISC列中有一些未格式化的数据。如何添加XML声明?对此有任何建议对我有很大的帮助。

SELECT
    1 AS Tag,
    NULL AS Parent,
    NULL AS 'Employee!1!',
    NULL AS 'EMP!2!EMP_ID_NR',
    NULL AS 'EMP!2!EMP_DEPT!Element',
    NULL AS 'EMP!2!EMP_MISC!cdata' 

UNION ALL

SELECT
    2 AS Tag,
    1 AS Parent, 
    NULL, 
    EMP.EMP_ID,
    EMP_DEPT,
    EMP_MISC 

FROM 
    EMPLOYEE EMP, DEPARTMENT DEPT  
WHERE 
    EMP.EMP_ID = DEPT.EMP_ID
FOR XML EXPLICIT 

0 个答案:

没有答案