Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

how can I update an xml by variable? Expand / Collapse
Author
Message
Posted Saturday, February 8, 2014 2:26 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Thursday, September 24, 2015 2:56 AM
Points: 42, Visits: 125
Hello
I want to update my xml node by a variable, I use code bellow, but it didn't work could you help me.


declare @urlRedirect nvarchar(4000)
set @urlRedirect=N'www.google.com'
declare @userxml xml
set @userxml=N'<user>
<information>
<userkey>0</userkey>
<domainname><![CDATA[192.168.0.97]]></domainname>
<ip>192.168.0.97:2007</ip>
<from><![CDATA[http://192.168.0.97/default.htm]]></from>
<time>02/08/2014 08:08:57 ق.ظ</time>
<q>https://www.google.com</q>
</information>
<urlarea>
<url>login.htm</url>
</urlarea>
<formarea>
<user><![CDATA[sa]]></user>
<pass><![CDATA[sa]]></pass>
<B1><![CDATA[Submit]]></B1>
<hascdata>false</hascdata>
</formarea>
<cookiearea></cookiearea>
</user>'
SET @Userxml.modify('replace value of (/urlarea/url/text())[1] with sql:variable("@urlRedirect")')
select @userxml

Post #1539479
Posted Saturday, April 12, 2014 2:31 PM
SSCertifiable

SSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiableSSCertifiable

Group: General Forum Members
Last Login: Today @ 1:39 PM
Points: 5,843, Visits: 15,642
The query just has an incorrect path, this works:


declare @urlRedirect nvarchar(4000)
set @urlRedirect=N'www.google.com'
declare @userxml xml
set @userxml=N'<user>
<information>
<userkey>0</userkey>
<domainname><![CDATA[192.168.0.97]]></domainname>
<ip>192.168.0.97:2007</ip>
<from><![CDATA[http://192.168.0.97/default.htm]]></from>
<time>02/08/2014 08:08:57 ?.?</time>
<q>https://www.google.com</q>
</information>
<urlarea>
<url>login.htm</url>
</urlarea>
<formarea>
<user><![CDATA[sa]]></user>
<pass><![CDATA[sa]]></pass>
<B1><![CDATA[Submit]]></B1>
<hascdata>false</hascdata>
</formarea>
<cookiearea></cookiearea>
</user>'
SET @Userxml.modify('replace value of (/user/urlarea/url/text())[1] with sql:variable("@urlRedirect")')
select @userxml

Post #1561241
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse