|
RSS Feed - WebSphere MQ Support
|
RSS Feed - Message Broker Support
|
 |
|
SELECT syntax for repeats within repeats |
« View previous topic :: View next topic » |
Author |
Message
|
brokendrum |
Posted: Mon Mar 10, 2003 2:19 am Post subject: SELECT syntax for repeats within repeats |
|
|
Apprentice
Joined: 14 Jan 2003 Posts: 34
|
Example message:
<XML>
<SectionA>
<Field1>data</Field1>
<Field1>data2</Field1>
</SectionA>
<SectionA>
<Field1>data3</Field1>
<Field1>data4</Field1>
<Field1>data5</Field1>
</SectionA>
</XML>
The message could contain many repeats of 'SectionA' and/or many repeats of 'Field1' within each of those occurances of 'SectionA'.
I need to access the field which contains, for example 'data4' which can be identified by containing the string 'data4'. I could do this with IF/WHILE statements within each other but I understand I could use SELECT instead. What ESQL would I use to do this? |
|
Back to top |
|
 |
philip.baker |
Posted: Mon Mar 10, 2003 1:26 pm Post subject: |
|
|
 Voyager
Joined: 21 Mar 2002 Posts: 77 Location: Baker Systems Consulting, Inc. - Tampa
|
brokerndrum,
The following ESQL will work for what you asked:
DECLARE I INTEGER;
SET I = 1;
WHILE I < CARDINALITY(InputRoot.*[]) DO
SET OutputRoot.*[I] = InputRoot.*[I];
SET I=I+1;
END WHILE;
-- Enter SQL below this line. SQL above this line might be regenerated, causing any modifications to be lost.
DECLARE SectionIndex INT;
DECLARE FieldIndex INT;
DECLARE FindString CHAR;
DECLARE Temp CHAR;
SET FindString = 'data4';
SET OutputRoot.XML.root.SectionAField1 = 'Nothing Found';
SET SectionIndex = 1;
WHILE SectionIndex <= CARDINALITY(InputRoot.XML.XML.SectionA[]) DO
SET FieldIndex = 1;
IF ( InputRoot.XML.XML.SectionA[SectionIndex].Field1[FieldIndex] IS NOT NULL ) THEN
WHILE FieldIndex <= CARDINALITY(InputRoot.XML.XML.SectionA[SectionIndex].Field1[]) DO
SET Temp = InputRoot.XML.XML.SectionA[SectionIndex].Field1[FieldIndex];
IF (Temp = FindString) THEN
SET OutputRoot.XML.root.SectionAField1=Temp;
END IF;
SET FieldIndex = FieldIndex + 1;
END WHILE;
END IF;
SET SectionIndex = SectionIndex + 1;
END WHILE;
Which, it seems as I reread you request, is the method you already know. I'll get back to you on the SELECT question. _________________ Regards,
Phil |
|
Back to top |
|
 |
lillo |
Posted: Tue Mar 11, 2003 12:07 am Post subject: |
|
|
Master
Joined: 11 Sep 2001 Posts: 224
|
Hi,
I haven´t try the code, but i have a suggestion to improve the performance. The following code
Code: |
WHILE SectionIndex <= CARDINALITY(InputRoot.XML.XML.SectionA[]) DO
|
could be replace with
Code: |
DECLARE COUNTER INTEGER;
SET COUNTER=CARDINALITY(InputRoot.XML.XML.SectionA[];
WHILE I < COUNTER DO |
Another suggestion, also to improve the performance, is change the code
Code: |
WHILE SectionIndex <= CARDINALITY(InputRoot.XML.XML.SectionA[]) DO
SET FieldIndex = 1;
IF ( InputRoot.XML.XML.SectionA[SectionIndex].Field1[FieldIndex] IS NOT NULL ) THEN
WHILE FieldIndex <= CARDINALITY(InputRoot.XML.XML.SectionA[SectionIndex].Field1[]) DO
SET Temp = InputRoot.XML.XML.SectionA[SectionIndex].Field1[FieldIndex];
IF (Temp = FindString) THEN
SET OutputRoot.XML.root.SectionAField1=Temp;
END IF;
SET FieldIndex = FieldIndex + 1;
END WHILE;
END IF;
SET SectionIndex = SectionIndex + 1;
END WHILE; |
with the following
Code: |
DECLARE refSectionIndex REFERENCE TO InputRoot.XML.XML.SectionA[1];
WHILE LASTMOVE(refSectionIndex) DO
SET FieldIndex = 1;
IF ( refSectionIndex.Field1[FieldIndex] IS NOT NULL ) THEN
WHILE FieldIndex <= CARDINALITY(InputRoot.XML.XML.SectionA[SectionIndex].Field1[]) DO
SET Temp = refSectionIndex.Field1[FieldIndex];
IF (Temp = FindString) THEN
SET OutputRoot.XML.root.SectionAField1=Temp;
END IF;
SET FieldIndex = FieldIndex + 1;
END WHILE;
END IF;
MOVE refSectionIndex NEXTSIBLING NAME FIELDNAME(refSectionIndex);
END WHILE; |
I just change the first while. It could be possible to change the second while in either way, but I just wanted to show how to change the original code to improve performance not change the original code.
Cheers, _________________ Lillo
IBM Certified Specialist - WebSphere MQ |
|
Back to top |
|
 |
|
|
 |
|
Page 1 of 1 |
|
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
|
|
|
|