See information about the latest product version
References & navigating the message tree
Navigation is the process of accessing elements in the message tree. You can access them in the Compute, JavaCompute, .NETCompute, PHPCompute, and Mappingnodes. The cost of accessing elements is not always apparent and is difficult to separate from other processing costs.
SET Description = InputBody.Level1.Level2.Level3.Description.Line[1];
<Level1>
<Level2>
<Level3>
<Description>
<Line>1</Line>
</Description>
</Level3>
</Level2>
</Level1>
The broker runtime accesses the message tree, starting at the correlation Root, and then moves down the tree to Level1, then Level2, then Level3, then Description, and finally it finds the first instance of the Line array. If you have this same statement in the next line of your ESQL module, then the same navigation takes place all over again. There is no cache to the last referenced element in the message tree because the access to the tree is intended to be dynamic to take account of the fact that it might change structure from one statement to another. This behavior can lead to repeated sets of navigation and traversing through the elements in a tree. If it is a large message tree, then the cost of navigation can become significant, leading to poor efficiency of your code.Therefore, to reduce the memory usage of tree navigation, it is recommended that you use a reference variable (for ESQL) or reference pointers (for Java™). Use this technique to save a pointer to a specific place in the message tree, and move it from one field to next as needed.
DECLARE refDescPtr REFERENCE TO InputRoot.XMLNSC.Level1.Level2.Level3.Description;
Use
the correlation name refDescPtr.Line to access the element
Line of the message tree.Use REFERENCE and MOVE statements to reduce the amount of navigation within the message tree and improve performance. This technique can be useful when you are constructing many SET or CREATE statements: Rather than navigating to the same branch in the tree, you can use a REFERENCE variable to establish a pointer to the branch and then use the MOVE statement to process one field at a time.
DECLARE refToLevel2 REFERENCE TO InputRoot.XMLNSC.Level1.Level2;
DECLARE refToLevel3 REFERENCE TO refToLevel2.Level3;
SET OutputRoot.XMLNSC.Level1.Level2.Level3.Description.Line[1]='1';
DECLARE outRef REFERENCE TO OutputRoot.XMLNSC.Level1.Level2.Level3.Description;
SET outRef.Line2 = '2';
SET outRef.Line3 = '3';
SET outRef.Line4 = '4';
SET outRef.Line5 = '5';
DECLARE myChar CHAR;
DECLARE inputRef REFERENCE TO InputRoot.XMLNSC.Level1.Level2.Level3.Descritpion.Line[1];
WHILE LASTMOVE(inputRef) DO
SET myChar = inputRef;
MOVE inputRef NEXTSIBLING NAME 'Line'; --Repearing record
END WHILE;
In summary, use reference variables or reference pointers to avoid repeated traversing and referencing of the elements that are caused by loops and other ineffective tree navigation.