-1

xml.modify当存在具有别名命名空间的节点时如何使用修改 XML 属性值

例如 XML 是:

<ar:archive xmlns:d="http://guidewire.com/cc/p04_00406_a09_01855_00558/domain" 
            xmlns:o="http://guidewire.com/cc/p04_00406_a09_01855_00558/other" 
            xmlns:ar="http://guidewire.com/archiving" 
            xmlns:i="http://guidewire.com/importing" 
            platform-major="4" platform-minor="406" 
            application-major="9" application-minor="1855" extension="558" 
            importing-schema-version="2.0" archving-schema-version="1.0" 
            root-ref="root" archive-date="2012-10-04T02:02:30.44-05:00">
   <d:Company id="d55" FaxPhone="1234567890" /> 
</ar:archive>

我想修改 to 的FaxPhone1234

4

1 回答 1

0

xml.modify似乎表明您可能正在为此使用 SQL Server - 对吗?

如果是这样 - 使用此代码来实现您正在寻找的内容:

// define XML namespace aliases for the two relevant namespaces
;WITH XMLNAMESPACES('http://guidewire.com/cc/p04_00406_a09_01855_00558/domain' AS d, 
                    'http://guidewire.com/archiving' AS ar)
UPDATE 
    dbo.YourTableNameHere
SET 
    YourXmlColumn.modify('replace value of (ar:archive/d:Company/@FaxPhone)[1] with "1234"')
WHERE 
    (some condition here to find the right row in the table ...)
于 2012-11-23T11:05:28.853 回答