问题
Replace <apipAccessbility>
element of this content with a new element in multiple rows with a column of type 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>
Once element is updated it should look like this:
<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>
回答1:
You could use modify and delete:
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;
LiveDemo
Output:
<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>
来源:https://stackoverflow.com/questions/35873792/replace-the-xml-element-with-new-element-in-sql-server