【问题标题】:Delete multiple XmlData sibling nodes with .remove()使用 .remove() 删除多个 XmlData 兄弟节点
【发布时间】:2014-01-16 20:51:19
【问题描述】:

这个问题类似于Deleting Multiple Nodes in Single XQuery for SQL Server。不同的是我想不加选择地删除文档中的所有节点。

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 节点。我可以删除所有节点而不必一次删除一个吗?

【问题讨论】:

  • DocumentXml 是一个 xml 非空列:DocumentXml (XML(.), not null) 是 SSMS 显示的内容。但错误仍然存​​在。

标签: xml sql-server-2008 xml-dml


【解决方案1】:

试试这个查询:

UPDATE tblXmlDocumentData
SET DocumentXml.modify('delete (//Attachment)') 
Where DocumentId = 1

【讨论】:

  • 我不久前意识到我的错误。 SET DocumentXml = Document... 是导致错误的原因。
猜你喜欢
  • 1970-01-01
  • 2014-02-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多