Author |
Message
|
mbsk |
Posted: Tue Oct 23, 2012 9:42 am Post subject: ESQL tree walking question |
|
|
Newbie
Joined: 23 Oct 2012 Posts: 4
|
newbie question from newbie. I am looking to parse an incoming XML message looking like the below:
Quote: |
<Message>
...
...
<Properties>
<Property_Name>abc</Property_Name> <Property_Value>123</Property_Value>
<Property_Name>def</Property_Name> <Property_Value>456</Property_Value>
</Properties>
...
</Message>
|
tags from the XML and populate tot he RFH2. how do I recursively read these Property names and values since the tags are all of the same name.
Should it be something like :
Quote: |
Declare ptrProperties REFERENCE TO InputRoot.XMLNSC.Message.Properties;
Whle lastmove(ptrProperties) DO
IF ptrProperties.Property is not null THEN
SET OutputRoot.MQRFH2.usr.Property = ptrProperties.Property_Name;
SET OutputRoot.MQRFH2.usr.Value = ptrProperties.Property_Value
END IF;
move ptrProperties lastchild;
END WHILE;
|
been trawling through the forums and esql documentation a bit but a little confused what ESQL constructs an logic path to use. also plan to be getting trained on this soon. |
|
Back to top |
|
 |
mqjeff |
Posted: Tue Oct 23, 2012 9:58 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
You have a single instance of Properties.
You have multiple instances of Property_Name and Property_Value.
The code you've posted is looping over the instances of Properties.
Code: |
Declare ptrProperties REFERENCE TO InputRoot.XMLNSC.Message.Properties.Property_Name;
Whle lastmove(ptrProperties) DO
IF fieldname(ptrProperties) = 'Property_Name' THEN
SET OutputRoot.MQRFH2.usr.Property = ptrProperties.Property_Name;
else if fieldName(ptrProperties) = 'Property_Value'
SET OutputRoot.MQRFH2.usr.Value = ptrProperties.Property_Value
END IF;
move ptrProperties NEXTSIBLING;
END WHILE; |
|
|
Back to top |
|
 |
mbsk |
Posted: Tue Oct 23, 2012 11:04 am Post subject: |
|
|
Newbie
Joined: 23 Oct 2012 Posts: 4
|
you mean as below ?
Quote: |
Declare ptrProperties REFERENCE TO InputRoot.XMLNSC.Message.Properties.Property_Name;
Whle lastmove(ptrProperties) DO
IF ptrProperties is not null THEN
SET OutputRoot.MQRFH2.usr.Property = ptrProperties;
SET OutputRoot.MQRFH2.usr.Value = ptrProperties.Property_Value
END IF;
move ptrProperties lastchild;
END WHILE;
|
Then how do i reference the corresponding Property_Value for the Property_Name tag being looped over? would the above line :
SET OutputRoot.MQRFH2.usr.Value = ptrProperties.Property_Value
work or should that be something else?
thx |
|
Back to top |
|
 |
mqjeff |
Posted: Tue Oct 23, 2012 11:13 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
Look at the code i posted again.
But that, of course, will only create one OutputRoot.MQRFH2.usr.Property and OutputRoot.MQRFH2.usr.Value.
You could revert to an easier, but less performant structure, and use
Code: |
set OutputRoot.MQRFH2.usr.Property[1]=InputRoot.XMLNSC.Mesage.Properties.Property_Name |
and likewise with Property_value and [2], [3], etc or a counter.
Or you could also create an additional reference that pointed to OutputRoot.MQRFH2.usr and then create additional Property and Value elements. |
|
Back to top |
|
 |
mqsiuser |
Posted: Wed Oct 24, 2012 12:15 am Post subject: Re: ESQL tree walking question |
|
|
 Yatiri
Joined: 15 Apr 2008 Posts: 637 Location: Germany
|
Code: |
<Message>
...
<Properties>
<Property_Name>abc</Property_Name>
<Property_Value>123</Property_Value>
<Property_Name>def</Property_Name>
<Property_Value>456</Property_Value>
</Properties>
...
</Message> |
Not tested (and please forgive mistakes (just tell me then I'll fix them)... I am actually a bit out of practice):
Code: |
DECLARE rOut REFERENCE TO OutputRoot;
CREATE LASTCHILD OF rOut AS rOut NAME 'MQRFH2'; -- If you have set OutputRoot.MQRFH2.CodedCharSetId(or something else already, then this is not necessary: This line actually must be removed then)
CREATE LASTCHILD OF rOut AS rOut NAME 'usr';
DECLARE rIn REFERENCE TO InputRoot.XMLNSC.Message.Properties;
MOVE rIn FIRSTCHILD NAME 'Property_Name'; -- Do a "MOVE", so that the "LASTMOVE" in the next line is TRUE (or FALSE)!
WHILE LASTMOVE(rIn) DO
DECLARE rProperty REFERENCE TO rOut;
CREATE LASTCHILD OF rProperty AS rProperty NAME 'Property' VALUE FIELDVALUE(rIn);
MOVE rIn NEXTSIBLING NAME 'Property_Value';
CREATE NEXTSIBLING OF rProperty AS rProperty NAME 'Value' VALUE FIELDVALUE(rIn);
MOVE rIn NEXTSIBLING NAME 'Property_Name';
END WHILE; |
I have also removed / excluded checks for null: You have to add custom code (according to the logic that you want to have) to include them.
You need to concentrate and carefully think about (all situations that may/can happen) to put these (null checks) in properly.
You also have to concentrate and work carefully for writing (and think about all cases that can happen) when writing tree walking code.
There is no easy solution. _________________ Just use REFERENCEs |
|
Back to top |
|
 |
mbsk |
Posted: Thu Nov 15, 2012 3:01 pm Post subject: |
|
|
Newbie
Joined: 23 Oct 2012 Posts: 4
|
ive adapted this to my flow and am able to see the RFH2 header being populated in the debugger. but, when I browse the message that has been output from MQ Explorer, I see nothing. Also, if I were to instead use an inout message as below :
Code: |
<Message>
...
<Properties>
<Property Name="abc" Value"123"</Property>
<Property Name="def" Value"456"</Property>
</Properties>
...
</Message>
|
I saw something about (XML.Attrib) but not sure how to adapt it to tree walking? |
|
Back to top |
|
 |
mqsiuser |
Posted: Fri Nov 16, 2012 2:34 am Post subject: |
|
|
 Yatiri
Joined: 15 Apr 2008 Posts: 637 Location: Germany
|
Can you try out using IDENTITY:
Code: |
CREATE LASTCHILD OF rProperty AS rProperty IDENTITY (XML.Attribute)property VALUE FIELDVALUE(rIn); |
|
|
Back to top |
|
 |
mbsk |
Posted: Wed Nov 21, 2012 10:07 am Post subject: |
|
|
Newbie
Joined: 23 Oct 2012 Posts: 4
|
been trying this using the information outlined at :
http://publib.boulder.ibm.com/infocenter/wmbhelp/v7r0m0/index.jsp?topic=%2Fcom.ibm.etools.mft.doc%2Fak04950_.htm
However, given an input xml field like
Quote: |
<Property Name="Property_1" Value="Value_1"/>
<Property Name="Property_2" Value="Value_2"/>
<Property Name="Property_3" Value="Value_3"/>
|
How would the create lastchild statement look like. I tried somethig like :
Code: |
CREATE LASTCHILD OF rPROPERTY AS rPROPERTY NAME IDENTITY(XML.Attribute)Property:Name Value (XML.Attribute)Property:Value
|
but this doesnt seem to work and the debugger skips over the lines completely. not sure why? any pointers? |
|
Back to top |
|
 |
lancelotlinc |
Posted: Wed Nov 21, 2012 10:10 am Post subject: |
|
|
 Jedi Knight
Joined: 22 Mar 2010 Posts: 4941 Location: Bloomington, IL USA
|
Your deployed code may be out of sync. Delete the objects in your EG and redeploy.
Also --
Don't rely on the interactive debugger. Use Trace nodes instead. _________________ http://leanpub.com/IIB_Tips_and_Tricks
Save $20: Coupon Code: MQSERIES_READER |
|
Back to top |
|
 |
|