|
RSS Feed - WebSphere MQ Support
|
RSS Feed - Message Broker Support
|
 |
|
IF condition not working as expected |
« View previous topic :: View next topic » |
Author |
Message
|
priyatumu |
Posted: Wed Nov 04, 2015 8:13 am Post subject: IF condition not working as expected |
|
|
Newbie
Joined: 04 Nov 2015 Posts: 2
|
Hi All,
My code
Code: |
IF (InputRoot.XMLNSC.breakfast_menu.food[vIntCount].sex = 'M') THEN
SET vINTFoodCount = CARDINALITY(InputRoot.XMLNSC.breakfast_menu.food[]);
WHILE vIntCount <= vINTFoodCount DO
SET OutputRoot.XMLNSC.menu.food[vIntCount].name = InputRoot.XMLNSC.breakfast_menu.food[vIntCount].name ;
SET OutputRoot.XMLNSC.menu.food[vIntCount].price = InputRoot.XMLNSC.breakfast_menu.food[vIntCount].price ;
SET OutputRoot.XMLNSC.menu.food[vIntCount].description = InputRoot.XMLNSC.breakfast_menu.food[vIntCount].description ;
SET OutputRoot.XMLNSC.menu.food[vIntCount].calories = InputRoot.XMLNSC.breakfast_menu.food[vIntCount].calories ;
SET vIntCount = vIntCount + 1;
END WHILE;
ELSEIF (InputRoot.XMLNSC.breakfast_menu.food[vIntCount].sex = 'F') THEN
SET vINTFoodCount = CARDINALITY(InputRoot.XMLNSC.breakfast_menu.food[]);
--
--
WHILE vIntCount <= vINTFoodCount DO
SET OutputRoot.XMLNSC.menu.food[vIntCount].name = InputRoot.XMLNSC.breakfast_menu.food[vIntCount].name ;
SET OutputRoot.XMLNSC.menu.food[vIntCount].price = InputRoot.XMLNSC.breakfast_menu.food[vIntCount].price ;
SET OutputRoot.XMLNSC.menu.food[vIntCount].description = InputRoot.XMLNSC.breakfast_menu.food[vIntCount].description ;
SET OutputRoot.XMLNSC.menu.food[vIntCount].calories = InputRoot.XMLNSC.breakfast_menu.food[vIntCount].calories ;
SET vIntCount = vIntCount + 1;
END WHILE;
--
-- --SET OutputLocalEnvironment.Destination.MQ.DestinationData.queueName = SIMPLE_OUT;
END IF; |
Problem with this code is it just checks for the first child under'food' and outputs it.Can somebody help me with this?
My Input XML
Code: |
<breakfast_menu>
<food>
<name>Belgian Waffles</name>
<price>$5.95</price>
<description>..Two of our famous Belgian Waffles with plenty of real maple syrup..</description>
<calories>650</calories>
<sex>F</sex>
</food>
<food>
<name>Strawberry Belgian Waffles</name>
<price>$7.95</price>
<description>..Light Belgian waffles covered with strawberries and whipped cream..</description>
<calories>900</calories>
<sex>M</sex>
</food>
<food>
<name>Berry-Berry Belgian Waffles</name>
<price>$8.95</price>
<description>..Light Belgian waffles covered with an assortment of fresh berries and whipped cream..</description>
<calories>900</calories>
<sex>M</sex>
</food>
<food>
<name>French Toast</name>
<price>$4.50</price>
<description>..Thick slices made from our homemade sourdough bread..</description>
<calories>600</calories>
<sex>F</sex>
</food>
<food>
<name>Homestyle Breakfast</name>
<price>$6.95</price>
<description>..Two eggs, bacon or sausage, toast, and our ever-popular hash browns..</description>
<calories>950</calories>
<sex>M</sex>
</food>
</breakfast_menu> |
|
|
Back to top |
|
 |
Vitor |
Posted: Wed Nov 04, 2015 8:19 am Post subject: |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
If this is an attempt to get the training and tutoring you ask for here, then it's going to end badly for you.
Two points:
From a pure code point of view, you have the increment (and general handling) of vIntCount wrong if you want it to check all the elements - this wouldn't work in Java or anything else;
Writing code in broker that uses CARDINALITY and an index like this is hideously inefficient - look up REFERENCE variable and the CREATE statement.
This last is why you need to spend a lot of time reading the documentation and/or getting some proper training. Broker is not a straightforward thing. _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
mqjeff |
Posted: Wed Nov 04, 2015 8:19 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
You should use reference variables instead of cardinality counts.
A user trace would show how the loop is executing and might show where your counter is not being used correctly. _________________ chmod -R ugo-wx / |
|
Back to top |
|
 |
mpong |
Posted: Thu Nov 05, 2015 11:29 pm Post subject: |
|
|
Disciple
Joined: 22 Jan 2010 Posts: 164
|
what is the point of writing if and else if condition when you are applying same processing mechanism for both. |
|
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
|
|
|
|