Re: replace value of empty element?
- From: "Denis Ruckebusch [MSFT]" <denisruc@xxxxxxxxxxxxxxxxxxxx>
- Date: Thu, 19 Apr 2007 15:07:27 -0700
In the first case, when you use expression (/root/test/text())[1] you refer to
something that doesn't exist (there is no text node under element test) and
therefore nothing gets updated.
What you need to do is insert a new text node inder element "test" like this
declare @xml xml
set @xml = '<root><test></test></root>'
set @xml.modify('insert text{"test new value"} as first into (/root/test)[1] ')
select @xml
I hope this helps.
Denis Ruckebusch
--
This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm
<doctorphan@xxxxxxxxx> wrote in message
news:1177013246.440921.259810@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Hi,
In SQL 2005, I have a XML with an one element with an empty value like
so:
<root>
<test></test>
</root>
When I try and replace the value of (/root/test) it does not seem to
work:
declare @xml xml
set @xml = '<root><test></test></root>'
set @xml.modify('replace value of (/root/test/text())[1] with "test
new value"')
select @xml
returns this:
<root>
<test></test>
</root>
If however the element has a value already like so:
<root>
<test>some old value here already</test>
</root>
and I re-rerun the statement above:
declare @xml xml
set @xml = '<root><test></test></root>'
set @xml.modify('replace value of (/root/test/text())[1] with "test
new value"')
select @xml
returns this:
<root>
<test>test new value</test>
</root>
Is something wrong there?
.
- Follow-Ups:
- Re: replace value of empty element?
- From: doctorphan
- Re: replace value of empty element?
- References:
- replace value of empty element?
- From: doctorphan
- replace value of empty element?
- Prev by Date: replace value of empty element?
- Next by Date: Re: replace value of empty element?
- Previous by thread: replace value of empty element?
- Next by thread: Re: replace value of empty element?
- Index(es):
Relevant Pages
|