Constructing an XML message tree

When constructing an XML message tree, consider the order of fields in the tree.

About this task

Order of fields in the message tree

When you create an XML output message in a Compute node, the order of your lines of ESQL code is important, because the message elements are created in the order that you code them.

Consider the following XML message:
<Order>
  <ItemNo>1</ItemNo>
  <Quantity>2</Quantity>
</Order> 

If you want to add a DocType Declaration to this, insert the DocType Declaration before you copy the input message to the output message.

For example:
SET OutputRoot.XMLNS.(XML.XmlDecl) = '';
SET OutputRoot.XMLNS.(XML.XmlDecl).(XML.Version) = '1.0';
SET OutputRoot.XMLNS.(XML.DocTypeDecl)Order ='';
SET OutputRoot.XMLNS.(XML.DocTypeDecl).(XML.SystemId)  	= 'NewDtdName.dtd';
SET OutputRoot = InputRoot;
  -- more ESQL -- 

If you put the last statement to copy the input message before the XML-specific statements, the following XML is generated for the output message.

<Order>
  <ItemNo>1</ItemNo>
  <Quantity>2</Quantity>
</Order>
<?xml version="1.0"?> 

This is not well-formed XML and causes an error when it is written from the message tree to a bit stream in the output node.

Setting the field type

If you copy a message tree from input to output without changing the domain, most of the syntax elements will be created by the parser ( XMLNSC or XMLNS ) and their field types will be correct. However, if you construct your message tree from a database query, or from another parser's message tree, you must ensure that you identify each syntax element correctly by using its field type. You can find full details of the field type constants used by XMLNSC and XMLNS in the following topics: