Posted: Tue Apr 18, 2006 1:13 am Post subject: Problem with updating list/repeating structure in wbimb/esql
Newbie
Joined: 26 Feb 2006 Posts: 1 Location: Mumbai
Hi,
Can some one help to find solution for below mention problem.
I have a list strucutre in a XML (repeating compund structure at some point in input tree) and i have to update a particular list item based on the content of its element.
let say if i have
<myRoot>
<child1>
<a>1</a>
<b>1</b>
<c>1</c>
</child1>
<child1>
<a>2</a>
<b>2</b>
<c>2</c>
</child1>
<child1>
<a>3</a>
<b>3</b>
<c>3</c>
</child1>
<child1>
<a>4</a>
<b>4</b>
<c>4</c>
</child1>
</myRoot>
then can write some thing like this and i want set child1.a to 10 where child1.c=3
------------
declare ref reference to select T.* from OutputRoot.XML.myRoot.child1[] where T.c = 3;
if LASTMOVE then
SET ref.a=10;
end if;
-----------
In short can reference a data dynamically retrieved by select i any logical structure.
other wise to achieve this i need do following code which migth be cubersome perhaps no efficient
--------------------
declare cnt=1;
while cnt <= cardinality(OutputRoot.XML.myRoot.child1[] ) do
if InputRoot.XML.myRoot.child1[cnt] = 3 then
SET InputRoot.XML.myRoot.child1[cnt] = 10;
end if;
end while;
--------------------
Or is there any efficient way to implement solution without using select.
Your first snippet using reference is good. You should continue in that line.
You are accessing the OutputRoot.XML....why ?
You could rather fetch from the InputRoot itself and then copy the altered ref to the OutputRoot.
Also the check for LASTMOVE will only return true if you have done a MOVE before...I am not sure if DECLARE is equivalent to MOVE...
else you could simply point to the first instance of child1
Code:
declare ref reference to select T.* from OutputRoot.XML.myRoot.child1
and then MOVE IF ref.c=10....your LASTMOVE will then make sense.
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum