这个问题与在 SQL Server 的单个 XQuery 中删除多个节点有关。不同之处在于我想不加选择地删除文档中的所有节点。
XML:
<root>
<Attachment id="Holding_1_attachment_0">
<AttachmentData>(B64 Enconded string)</AttachmentData>
<MimeTypeTC tc="17" />
<AttachmentLocation tc="2">URL Reference</AttachmentLocation>
</Attachment>
<Attachment id="Holding_1_attachment_0">
<AttachmentData>(B64 Enconded string)</AttachmentData>
<MimeTypeTC tc="17" />
<AttachmentLocation tc="2">URL Reference</AttachmentLocation>
</Attachment>
<Attachment id="234">
<AttachmentBasicType tc="3">File</AttachmentBasicType>
<AttachmentSource>C:\Windows Ding.wav</AttachmentSource>
<AttachmentData>(B64 Enconded string)</AttachmentData>
<MimeTypeTC tc="7">WAV</MimeTypeTC>
<TransferEncodingTypeTC tc="4">Base64</TransferEncodingTypeTC>
<AttachmentLocation tc="1">Inline</AttachmentLocation>
<FileName>Windows Ding.wav</FileName>
</Attachment>
<Attachment id="234">
<AttachmentBasicType tc="3">File</AttachmentBasicType>
<AttachmentSource>C:\Windows Ding.wav</AttachmentSource>
<AttachmentData>(B64 Enconded string)</AttachmentData>
<MimeTypeTC tc="7">WAV</MimeTypeTC>
<TransferEncodingTypeTC tc="4">Base64</TransferEncodingTypeTC>
<AttachmentLocation tc="1">Inline</AttachmentLocation>
<FileName>Windows Ding2.wav</FileName>
</Attachment>
</root>
本质上,我有一个包含上述 XML 的巨大文档,我想要么删除所有Attachment
节点(包括子节点),要么删除AttachmentData
节点(我还没有完全决定要使用哪种方法)。
我尝试了以下方法来删除节点:
UPDATE tblXmlDocumentData
SET DocumentXml = DocumentXml.modify('delete (//Attachment)') /* or //Attachment/AttachmentData */
Where DocumentId = 1
SQL 回复的内容:
Incorrect use of the XML data type method 'modify'. A non-mutator method is expected in this context.
我假设这是因为我没有指定Attachment
要删除的节点。我可以删除所有节点而不必一次删除一个吗?