Author |
Message
|
hobybrown |
Posted: Wed Sep 11, 2002 8:38 am Post subject: How to set the value of an output xml element w/ attribute? |
|
|
Newbie
Joined: 11 Sep 2002 Posts: 3
|
I am trying to set the value of an output xml element with an attribute.
Example:
<outerelement>
<element attrib="AAAA">xxxx</element>
<element attrib="BBBB">yyyy</element>
<outerelement>
would like to change to:
<outerelement>
<element attrib="AAAA">xxxx</element>
<element attrib="BBBB">zzzz</element>
<outerelement>
Is there a way to do this using a simple 'SET' statement in ESQL? I have tried the following without success:
SET OutputRoot.XML.outerelement."element attrib=""BBBB""" = 'zzzz'; |
|
Back to top |
|
 |
lbrett |
Posted: Wed Sep 11, 2002 9:25 am Post subject: |
|
|
Novice
Joined: 24 Jan 2002 Posts: 20
|
For your example use
SET OutputRoot.XML.outerelement[2]='zzzz';
If you want to make the change based on value of the element attribute then use:
DECLARE A INTEGER;
DECLARE B INTEGER;
SET A = CARDINALITY(InputBody.outerelement[]);
SET B=1;
WHILE B <= A DO
IF (InputBody.outerelement[B].(XML.attr)attrib='BBBB') THEN
SET OutputRoot.XML.outerelement[B]='zzzz';
END IF;
SET B=B+1;
END WHILE; |
|
Back to top |
|
 |
philip.baker |
Posted: Wed Sep 11, 2002 10:29 am Post subject: |
|
|
 Voyager
Joined: 21 Mar 2002 Posts: 77 Location: Baker Systems Consulting, Inc. - Tampa
|
Or for a 'variation on a theme':
SET OutputRoot = InputRoot;
-- Enter SQL below this line. SQL above this line might be regenerated, causing any modifications to be lost.
DECLARE EIndex INTEGER;
DECLARE OEIndex INTEGER;
DECLARE Temp CHAR;
DECLARE TEST CHAR;
SET TEST = 'BBBB';
SET OEIndex = 1;
SET EIndex = 1;
IF (InputRoot.XML.outerelement IS NOT NULL) THEN
WHILE OEIndex <= CARDINALITY(InputRoot.XML.outerelement[]) DO
IF (InputRoot.XML.outerelement[OEIndex].element IS NOT NULL) THEN
WHILE EIndex <= CARDINALITY(InputRoot.XML.outerelement[OEIndex].element[]) DO
SET Temp = InputRoot.XML.outerelement[OEIndex].element[EIndex].(XML.attr)attrib;
IF ( Temp = TEST ) THEN
SET OutputRoot.XML.outerelement[OEIndex].element[EIndex]='zzzz';
SET OutputRoot.XML.outerelement[OEIndex].element[EIndex].(XML.attr)attrib='BBBB';
END IF;
SET EIndex = EIndex +1;
END WHILE;
END IF;
SET OEIndex = OEIndex +1;
END WHILE;
END IF;
Regards,
Phil |
|
Back to top |
|
 |
lbrett |
Posted: Wed Sep 11, 2002 10:42 am Post subject: |
|
|
Novice
Joined: 24 Jan 2002 Posts: 20
|
Sorry... my ESQL is a little incorrect You are trying to set the value of element and not outerelement.
============================
For your example use
SET OutputRoot.XML.outerelement.element[2]='zzzz';
If you want to make the change based on value of the element attribute then use:
DECLARE A INTEGER;
DECLARE B INTEGER;
SET A = CARDINALITY(InputBody.outerelement.element[]);
SET B=1;
WHILE B <= A DO
IF (InputBody.outerelement.element[B].(XML.attr)attrib='BBBB') THEN
SET OutputRoot.XML.outerelement.element[B]='zzzz';
END IF;
SET B=B+1;
END WHILE; |
|
Back to top |
|
 |
hobybrown |
Posted: Wed Sep 11, 2002 12:16 pm Post subject: |
|
|
Newbie
Joined: 11 Sep 2002 Posts: 3
|
Ibrett,
Thank you for your quick reply. Thanks to your initial lead, I finally got it to work. I had just figured out that your esql was slightly incorrect and was going to post the correction, but you have beaten me to it. Thank you for your help. Could not have figured it out without your help. |
|
Back to top |
|
 |
|