Re: locating the node and then replacing
- From: "Denis Ruckebusch [MSFT]" <denisruc@xxxxxxxxxxxxxxxxxxxx>
- Date: Fri, 12 May 2006 16:40:13 -0700
Hi Paul,
One of the ways to insert multiple nodes is to use the sequence
constructor like this
DECLARE @var XML
SET @var = '<root/>'
SET @var.modify('insert (<a>Data a</a> , <b/>) into /root[1]')
SELECT @var
The resulting instance will look like this
<root><a>Data a</a><b /></root>
You can also use an XPath expression that resolves to multiple nodes as
your source for the nodes to insert. Here's an example
DECLARE @var XML
SET @var = '<root><a>Data a</a><b /></root>'
SET @var.modify('insert /root/* into (/root/b)[1]')
SELECT @var
The resulting instance will look like this
<root><a>Data a</a><b><a>Data a</a><b /></b></root>
You can even use both the sequence constructor and XPath expressions
like this
DECLARE @var XML
SET @var = '<root><a>Data a</a><b /></root>'
SET @var.modify('insert (/root/a,/root/*) into (/root/b)[1]')
SELECT @var
The resulting instance will look like this
<root><a>Data a</a><b><a>Data a</a><a>Data a</a><b /></b></root>
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
"news.microsoft.com" <paulixml@xxxxxxxxxxx> wrote in message
news:uDsiqZddGHA.536@xxxxxxxxxxxxxxxxxxxxxxx
Hi
most of the example in BOL for xquery seem to have the xpath hardcoded
in the query, how do you search a xml document and then decide if you
should do an insert or a replace if you did not really know the exact
path of the node. Also, you can only insert one node at a time, how
do you insert more than one node at the same position.
thanks
Paul
.
- References:
- locating the node and then replacing
- From: news.microsoft.com
- locating the node and then replacing
- Prev by Date: Re: Don't want escape characters in results
- Next by Date: Re: Inserting Child Elements
- Previous by thread: locating the node and then replacing
- Next by thread: Don't want escape characters in results
- Index(es):