Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


how can I update an xml by variable?


how can I update an xml by variable?

Author
Message
bkshn
bkshn
SSC Rookie
SSC Rookie (42 reputation)SSC Rookie (42 reputation)SSC Rookie (42 reputation)SSC Rookie (42 reputation)SSC Rookie (42 reputation)SSC Rookie (42 reputation)SSC Rookie (42 reputation)SSC Rookie (42 reputation)

Group: General Forum Members
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


Eirikur Eiriksson
Eirikur Eiriksson
SSCertifiable
SSCertifiable (6.8K reputation)SSCertifiable (6.8K reputation)SSCertifiable (6.8K reputation)SSCertifiable (6.8K reputation)SSCertifiable (6.8K reputation)SSCertifiable (6.8K reputation)SSCertifiable (6.8K reputation)SSCertifiable (6.8K reputation)

Group: General Forum Members
Points: 6792 Visits: 17739
The query just has an incorrect path, this works:
Cool

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


Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search