Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
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: Tuesday, November 18, 2014 11:27 PM
Points: 37, Visits: 102
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
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Today @ 10:41 PM
Points: 2,533, Visits: 7,106
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