用 SQL 服务器中的新元素替换 XML 元素
Replace the XML element with new Element in SQL server
将此内容的 <apipAccessbility>
元素替换为具有类型 XML
:
的多行中的新元素
<Item title="1234" xmlns="http://www.imsglobal.org/xsd/imsqti_v2p2">
<ItemBody>xyz</ItemBody>
<apipAccessibility xmlns="http://www.imsglobal.org/xsd/apip/apipv1p0/imsapip_qtiv1p0">
<accessibilityInfo>
Blablah
</accessibilityInfo>
</apipAccessibility>
</Item>
元素更新后应该如下所示:
<Item title="1234" xmlns="http://www.imsglobal.org/xsd/imsqti_v2p2">
<ItemBody>xyz</ItemBody>
<apipAccessibility xmlns="http://www.imsglobal.org/xsd/apip/apipv1p0/imsapip_qtiv1p0"/>
</Item>
UPDATE tab
SET col.modify('
declare namespace NS="http://www.imsglobal.org/xsd/imsqti_v2p2";
declare namespace NS2="http://www.imsglobal.org/xsd/apip/apipv1p0/imsapip_qtiv1p0";
delete /NS:Item/NS2:apipAccessibility/*')
-- WHERE id = 1;
输出:
<Item xmlns="http://www.imsglobal.org/xsd/imsqti_v2p2" title="1234">
<ItemBody>xyz</ItemBody>
<apipAccessibility xmlns="http://www.imsglobal.org/xsd/apip/apipv1p0/imsapip_qtiv1p0" />
</Item>
将此内容的 <apipAccessbility>
元素替换为具有类型 XML
:
<Item title="1234" xmlns="http://www.imsglobal.org/xsd/imsqti_v2p2">
<ItemBody>xyz</ItemBody>
<apipAccessibility xmlns="http://www.imsglobal.org/xsd/apip/apipv1p0/imsapip_qtiv1p0">
<accessibilityInfo>
Blablah
</accessibilityInfo>
</apipAccessibility>
</Item>
元素更新后应该如下所示:
<Item title="1234" xmlns="http://www.imsglobal.org/xsd/imsqti_v2p2">
<ItemBody>xyz</ItemBody>
<apipAccessibility xmlns="http://www.imsglobal.org/xsd/apip/apipv1p0/imsapip_qtiv1p0"/>
</Item>
UPDATE tab
SET col.modify('
declare namespace NS="http://www.imsglobal.org/xsd/imsqti_v2p2";
declare namespace NS2="http://www.imsglobal.org/xsd/apip/apipv1p0/imsapip_qtiv1p0";
delete /NS:Item/NS2:apipAccessibility/*')
-- WHERE id = 1;
输出:
<Item xmlns="http://www.imsglobal.org/xsd/imsqti_v2p2" title="1234">
<ItemBody>xyz</ItemBody>
<apipAccessibility xmlns="http://www.imsglobal.org/xsd/apip/apipv1p0/imsapip_qtiv1p0" />
</Item>