2

Sql Server 2008 の xml フィールドから属性が欠落しているルート ノードのすべての子ノードを削除する正しい方法は何ですか?

私の Xml は次のようになります。属性が指定され<root>ていないすべての子ノードを削除したいln

<root>
  <title />
  <title />
  <questionphrase ln="nl">
    <xhtml />
  </questionphrase>
  <questionphrase ln="en">
    <xhtml />
  </questionphrase>
  <information ln="nl">
    <xhtml />
  </information>
  <information ln="en">
    <xhtml />
  </information>
  <title />
  <title ln="en">
     value
  </title>
  <label ln="en">
     value
  </label>
  <title />
  <title />
</root>

削除後、xml は次のようになります。

<root>
  <questionphrase ln="nl">
    <xhtml />
  </questionphrase>
  <questionphrase ln="en">
    <xhtml />
  </questionphrase>
  <information ln="nl">
    <xhtml />
  </information>
  <information ln="en">
    <xhtml />
  </information>
  <title ln="en">
     value
  </title>
  <label ln="en">
     value
  </label>
</root>
4

1 に答える 1

5

これを試して:

DECLARE @xml XML = '....'
SET @xml.modify('delete //root/*[not(@ln)]')

SQL フィドルのデモ

于 2013-01-29T09:58:41.220 に答える