Author |
Message
|
KSkelton |
Posted: Tue Oct 15, 2002 5:51 am Post subject: Checking repeating XML fields in a Filter node |
|
|
Apprentice
Joined: 28 Oct 2001 Posts: 45
|
Is it possible to check the value of a variable number of repeating XML fields in a filter node?
I know I can check a fix count by using something like this:
Body.XMLMULT.REPEAT[1] = 2 or
Body.XMLMULT.REPEAT[2] = 2 or
Body.XMLMULT.REPEAT[3] = 2
But what if I do not know the number of occurrences of the REPEAT field? |
|
Back to top |
|
 |
lillo |
Posted: Tue Oct 15, 2002 6:46 am Post subject: |
|
|
Master
Joined: 11 Sep 2001 Posts: 224
|
Hi,
Try the following code:
Code: |
DECLARE counter INTEGER;
DECLARE refElement REFERENCE TO Body.XMLMULT.REPEAT[1];
DECLARE ret BOOLEAN;
SET ret =TRUE;
WHILE (LASTMOVE(refElement) AND ret) DO
IF (refElement=2) THEN
SET ret = TRUE;
ELSE
SET ret = FALSE;
END IF;
MOVE refElement NEXTSIBLING NAME FIELDNAME(refElement);
END WHILE;
RETURN ret;
|
Cheers, _________________ Lillo
IBM Certified Specialist - WebSphere MQ |
|
Back to top |
|
 |
KSkelton |
Posted: Tue Oct 15, 2002 7:43 am Post subject: |
|
|
Apprentice
Joined: 28 Oct 2001 Posts: 45
|
Lillo,
Thanks for the code. I only had to modify it slightly to default to FALSE instead of TRUE so that the filter would return a true if a "2" was found. Like this...
SET ret = FALSE;
WHILE (LASTMOVE(refElement) = TRUE) AND (ret = FALSE) DO
Thanks again. |
|
Back to top |
|
 |
lillo |
Posted: Tue Oct 15, 2002 8:10 am Post subject: |
|
|
Master
Joined: 11 Sep 2001 Posts: 224
|
You are right. But I would add a if instead of modifying the boolean variable to false.
Code: |
IF Body.XMLMULT.REPEAT[1] IS NOT NULL THEN
-- WHILE CODE
ELSE
SET ret = FALSE;
END IF;
|
The reason for this change is that once you find a false you could finish the while loop. This will improve your performance.
Cheers, _________________ Lillo
IBM Certified Specialist - WebSphere MQ |
|
Back to top |
|
 |
mikek |
Posted: Tue Oct 29, 2002 11:37 pm Post subject: |
|
|
Newbie
Joined: 25 Jun 2002 Posts: 5
|
What you're looking for is the FOR statement (see eSQL Reference). It can be used to answer the questions:
Do ALL the repeating fields match this criteria?
Do ANY of the fields match my criteria? |
|
Back to top |
|
 |
Yanghui |
Posted: Wed Oct 30, 2002 4:33 am Post subject: |
|
|
Disciple
Joined: 08 May 2002 Posts: 151 Location: Dublin, Ireland
|
Hi, there,
I can't find the FOR statement in the ESQL Reference. Which version of this manual are you using? I know it exists since I can see it in the Compute node. Thanks a lot.
Regards
-Yanghui |
|
Back to top |
|
 |
mikek |
Posted: Wed Oct 30, 2002 4:41 am Post subject: |
|
|
Newbie
Joined: 25 Jun 2002 Posts: 5
|
We are using 2.1, but I seem to remember that it was available at least as early as 2.0.2. |
|
Back to top |
|
 |
tchagan |
Posted: Wed Oct 30, 2002 5:10 am Post subject: |
|
|
 Apprentice
Joined: 10 Feb 2002 Posts: 31
|
Hi,
your code using the FOR command in the filter should be :
FOR ANY Body.XMLMULT.REPEAT[] as A
(A = 2)
will return true if any A element is equal to 2
Terry |
|
Back to top |
|
 |
lillo |
Posted: Wed Oct 30, 2002 5:48 am Post subject: |
|
|
Master
Joined: 11 Sep 2001 Posts: 224
|
The FOR statement is available on WMQI 2.1 CSD3
Cheers, _________________ Lillo
IBM Certified Specialist - WebSphere MQ |
|
Back to top |
|
 |
wmqiguy |
Posted: Wed Oct 30, 2002 7:11 am Post subject: |
|
|
 Centurion
Joined: 09 Oct 2002 Posts: 145 Location: Florida
|
Just a quick note to consider from the ESQL reference (it is in the Referencing Repeating Fields portion of Chapter 2):
If a mixture of FALSE and UNKNOWN values are returned from the sub-predicate, an overall value of UNKNOWN is returned.
Great care must be taken to deal with the possibility of null values appearing. You are therefore recommended to write this filter with an explicit check on the existence of the field.
So you might consider:
FOR ANY Body.XMLMULT.REPEAT[] as A
( A IS NOT NULL AND A = 2)
Good Luck.  |
|
Back to top |
|
 |
|