ATTACH statement

The ATTACH statement attaches a portion of a message tree into a new position in the message hierarchy.

Syntax

Read syntax diagramSkip visual syntax diagramATTACHdynamic referenceTOfield referenceAS FIRSTCHILDLASTCHILDPREVIOUSSIBLINGNEXTSIBLING

The following example illustrates how to use the ATTACH statement, together with the DETACH statement described in DETACH statement, to modify a message structure. The dynamic reference supplied to the DETACH statement must point to a modifiable message tree such as Environment, LocalEnvironment, OutputRoot, OutputExceptionList, or InputLocalEnvironment.

There are some limitations on the use of ATTACH. In general, elements detached from the output trees of a Compute node are not attached to the environment or to input trees.

For example, if you take the following message:
<Data>
  <Order>
    <Item>cheese
        <Type>stilton</Type>
    </Item>
    <Item>bread</Item>
  </Order>
  <Order>
    <Item>garlic</Item>
    <Item>wine</Item>
  </Order>
 </Data>
the following ESQL statements:
SET OutputRoot = InputRoot;
DECLARE ref1 REFERENCE TO OutputRoot.XMLNSC.Data.Order[1].Item[1];
DETACH ref1;
ATTACH ref1 TO OutputRoot.XMLNSC.Data.Order[2] AS LASTCHILD;
result in the following new message structure:
<Data>
  <Order>
     <Item>bread</Item>
  </Order>
  <Order>
     <Item>garlic</Item>
     <Item>wine</Item>
     <Item>cheese
        <Type>stilton</Type>
     </Item>
  </Order>
 </Data>

For information about dynamic references see Creating dynamic field references.