Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Replace xml nodes in xml field using XQuery

Author  Topic 

WaterWolf
Starting Member

24 Posts

Posted - 2009-03-26 : 08:09:08
Hello,

I can't for the life of me figure out to replace an xml node in an xml field in my database for example:

<root>
<doo>
</fee>
</fi>
<fo>
</fum>
</fo>
</doo>
</root>

I want to update the xml in all fields so that all the subnodes of the <doo> node get replaced with </lalala > Eg:

<root>
<doo>
<lalala
</doo>
</root>

I've tried doing something like this:
UPDATE tTable SET XmlStuff.modify('replace value of node /root/doo[1] with "</lalala>"')


but I keep getting an error saying "The target of 'replace value of' must be a non-metadata attribute or an element with simple typedcontent" no matter how many [1]s I throw into it ! I'm new to Xquery so I'm not really sure what I'm doing...

WaterWolf
Starting Member

24 Posts

Posted - 2009-03-26 : 08:30:20
Oops... I should at least post my xml properly !


<root>
<doo>
<fee />
<fi />
<fo>
<fum />
</fo>
</doo>
</root>



<root>
<doo>
<lalala />
</doo>
</root>
Go to Top of Page
   

- Advertisement -