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

时间:2012-11-23 08:58:15

标签: xml

如果存在具有别名命名空间的节点

,如何使用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>

我想将FaxPhone的值修改为1234

1 个答案:

答案 0 :(得分: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 ...)