Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql server 从SQL中XML的所有节点中删除属性_Sql Server_Xml Parsing_Xquery Sql - Fatal编程技术网

Sql server 从SQL中XML的所有节点中删除属性

Sql server 从SQL中XML的所有节点中删除属性,sql-server,xml-parsing,xquery-sql,Sql Server,Xml Parsing,Xquery Sql,如何通过T-sql从XML的所有节点删除属性CRS。希望删除属性CRS(如果XML中存在) <list> <group id="12345"> <entry id="1" type="Audio" lang="en-us"> <p data-its-style=""> <audio xmlns="http://www.imsglobal.org/xsd/imsqtiv2p2_html5_v

如何通过T-sql从XML的所有节点删除属性CRS。希望删除属性CRS(如果XML中存在)

   <list>
<group id="12345">
    <entry id="1" type="Audio" lang="en-us">
        <p data-its-style="">
            <audio xmlns="http://www.imsglobal.org/xsd/imsqtiv2p2_html5_v1p0" class="sound_explicit">
                <source crs="test1_en.ogg" type="audio/ogg; " src="1234.ogg" />
                <source crs="test1_en.m4a" type="audio/mp4;" src="4567.mp4" />
            </audio>
        </p>
    </entry>
</group>
<group id="67890">
    <entry id="4" type="Audio" lang="es-mx">
            <p data-its-style="">
            <audio xmlns="http://www.imsglobal.org/xsd/imsqtiv2p2_html5_v1p0"  class="sound_explicit">
                <source crs="test4_en.ogg" type="audio/ogg; " src="1234.ogg" />
                <source crs="test4_en.m4a" type="audio/mp4;" src="4567.mp4" />
            </audio>
        </p>
    </entry>
</group>

这应该能奏效

    DECLARE @xml XML = '<list>
    <group id="12345">
        <entry id="1" type="Audio" lang="en-us">
            <p data-its-style="">
                <audio xmlns="http://www.imsglobal.org/xsd/imsqtiv2p2_html5_v1p0" class="sound_explicit">
                    <source crs="test1_en.ogg" type="audio/ogg; " src="1234.ogg" />
                    <source crs="test1_en.m4a" type="audio/mp4;" src="4567.mp4" />
                </audio>
            </p>
        </entry>
    </group>
    <group id="67890">
        <entry id="4" type="Audio" lang="es-mx">
                <p data-its-style="">
                <audio xmlns="http://www.imsglobal.org/xsd/imsqtiv2p2_html5_v1p0"  class="sound_explicit">
                    <source crs="test4_en.ogg" type="audio/ogg; " src="1234.ogg" />
                    <source crs="test4_en.m4a" type="audio/mp4;" src="4567.mp4" />
                </audio>
            </p>
        </entry>
    </group>
    </list>'

    /*Before*/
    SELECT @xml
    /*Delete*/
    SET @xml.modify ('declare namespace ns="http://www.imsglobal.org/xsd/imsqtiv2p2_html5_v1p0";  delete list/group/entry/p/ns:audio/ns:source/@crs')
    /*After*/
    SELECT @xml 

请参阅下面的解决方案