|
RSS Feed - WebSphere MQ Support
|
RSS Feed - Message Broker Support
|
 |
|
strange behaviour when using cardinality and XML attributes |
« View previous topic :: View next topic » |
Author |
Message
|
JohnMetcalfe |
Posted: Fri Sep 17, 2004 9:02 am Post subject: strange behaviour when using cardinality and XML attributes |
|
|
 Apprentice
Joined: 02 Apr 2004 Posts: 40 Location: Edinburgh, Scotland
|
We have code that is attempting to 'walk' an XML tree
At each level we use the following code to find out if the XML element has any children
set childcount = cardinality(xmlfield.*[]);
If the xmlfield has NO children, cardinality returns 1.
If the xmlfield also contains attributes, the cardinality count includes these attributes. So if we have say, 3 children and 4 attributes, we will get a cardinality count of 8 (remember we get 1 even if they are no children)
This is not the behaviour we are expecting ! We want to ignore xml attributes as we walk through the XML tree (and were not expecting cardinality to count them!). Any ideas?
We are using WMQI 2.1 CSD3
The code we are using is as follows:
Code: |
declare childcount INTEGER;
declare xmlfield REFERENCE TO OutputRoot.XML.CSL.Message;
WHILE LASTMOVE(xmlfield) = TRUE
DO
set childcount = cardinality(xmlfield.*[]);
IF childcount > 1 THEN
move xmlfield FIRSTCHILD;
ELSE
IF xmlfield ='' THEN
set xmlfield.(XML.Content) = NULL; -- converts to single tag ending /
set xmlfield.(XML.Attribute)"xsi.nil" = 'true'; -- puts in nil attribute
END IF;
move xmlfield NEXTSIBLING;
IF LASTMOVE(xmlfield) = FALSE THEN -- reached end of children, time to go up
move xmlfield PARENT;
move xmlfield NEXTSIBLING;
END IF;
END IF;
END WHILE; |
|
|
Back to top |
|
 |
jefflowrey |
Posted: Fri Sep 17, 2004 9:30 am Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
Use the "type" option on MOVE...NEXTSIBLING (if it's still there). _________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
JohnMetcalfe |
Posted: Wed Sep 22, 2004 2:10 am Post subject: |
|
|
 Apprentice
Joined: 02 Apr 2004 Posts: 40 Location: Edinburgh, Scotland
|
Thanks for the suggestion
We changed the code so the initial count was
Code: |
set childcount = cardinality( xmlfield.(XML.Element)*[]) |
This gives us the correct number of child elements, and ignores the attributes.
However, we also tried to modify the NEXTSIBLING call, as follows
Code: |
move xmlfield NEXTSIBLING REPEAT TYPE; |
which I think you were suggesting, but it would not compile - told us this was invalid syntax . We are on WMQI 2.1 CSD3 - is this a WMBIMB feature? |
|
Back to top |
|
 |
jefflowrey |
Posted: Wed Sep 22, 2004 4:34 am Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
I think it may be 2.1 CSD4 syntax...
Or you could try the "TYPE <expr>" clause instead of the "REPEAT TYPE" clause.
The syntax you show is correct according to the last version of the ESQL Reference, here. _________________ I am *not* the model of the modern major general. |
|
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
|
|
|
|