简体   繁体   English

在SQL Server 2012中使用CDATA

[英]Use CDATA in SQL server 2012

I am trying to create a node in xml with CDATA in SQL server 2012. I use the code provided in https://stackoverflow.com/a/1429383/4158652 . 我试图在SQL Server 2012中使用CDATA在xml中创建一个节点。我使用https://stackoverflow.com/a/1429383/4158652中提供的代码。

There are two main problems 1- my data is not populated inside CDATA ie instrtext and hinttext. 主要有两个问题:1-我的数据未填充在CDATA中,即instrtext和hinttext。 2- extra props node in xml 2- XML中的额外道具节点

The code I have been using is 我一直在使用的代码是

SET @instrProps =
            (
            select * from (             
              SELECT
                    1 AS Tag,
                    NULL AS Parent,                     
                NULL AS 'props!1!instrtext!cdata',
                NULL AS 'props!1!hinttext!cdata',
                NULL AS 'props!1!score!Element'
            UNION ALL
            SELECT
                1 AS Tag,
                NULL AS Parent,                 
                @instText,
                @hintText,
                @score
                ) X             
            FOR XML EXPLICIT, ROOT('props')
  )
  select @instrProps as DiplayNode

I am expecting the node be 我期望节点是

       <props>
            <instrtext>
                <![CDATA[TExt in this node]]>
            </instrtext>
            <hinttext>
                <![CDATA[Text in thi node]]>
            </hinttext>
            <score>5.000</score>
        </props>

but it is coming like 但它来像

<props>
  <props />
  <props>
    <instrtext>TExt in this node</instrtext>
    <hinttext>TExt in this node</hinttext>
    <score>5</score>
  </props>
</props>

Please help. 请帮忙。

It appears you cannot retain CDATA when the XML data type is involved. 涉及XML数据类型时,您似乎无法保留CDATA。 See https://stackoverflow.com/a/9133622/864696 参见https://stackoverflow.com/a/9133622/864696

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM