When you refer to or set elements within an XML message body, you must use the correct field type constants, in ESQL field references, to address them.
The following table lists the field type constants for all valid elements.
Syntax element | field type constant |
---|---|
CDataSection | (XML.CDataSection) |
Comment | (XML.Comment) |
Content | (XML.Content) |
Element | (XML.Element) |
EntityReferenceEnd | (XML.EntityReferenceEnd) |
EntityReferenceStart | (XML.EntityReferenceStart) |
ProcessingInstruction | (XML.ProcessingInstruction) |
WhiteSpace | (XML.WhiteSpace) |
When a type is not present in a path element, the type of the syntax element is not important. That is, a path element of name matches any syntax element with the name of name, regardless of the element type. In the same way that a path element can specify a name and not a type, a path element can specify a type and not a name. This type of path element matches any syntax element that has the specified type, regardless of name. Consider the following example:
FIELDNAME(InputBody.(XML.Element)[1])
This example returns the name of the first element in the body of the message. The following example of generic XML shows when you must use types in paths:
<tag1 attr1='abc'> <attr1>123<attr1> </tag1>
The path InputBody.tag1.attr1 refers to the attribute called attr1, because attributes appear before nested elements in a syntax tree generated by an XML parser. To refer to the element called attr1 you must use a path:
InputBody.tag1.(XML.Element)attr1
Always include types in these cases to be explicit about which syntax element you are referring to.
The following ESQL:
SET OutputRoot.XML.Element1.(XML.Element)Attribute1 = '123';
is essentially shorthand for the following, fully-qualified path :
SET OutputRoot.XML.(XML.Element)Element1.(XML.Element)Attribute1. (XML.Content) = '123';
Consider the following XML:
<?xml version="1.0"?> <!DOCTYPE Order SYSTEM "Order.dtd"> <Order> <ItemNo>1</ItemNo> <Quantity>2</Quantity> </Order>
The path InputBody.Order refers to the (XML.DocTypeDecl) syntax element, because this appears before the XML Body in the syntax tree and has the same name. To refer to the element ItemNo, use a path InputBody.(XML.Element)Order.ItemNo. For example, consider the following XML input message:
<doc><i1>100</i1></doc>
To assign 112233 to <i1>, use the following ESQL expression:
SET OutputRoot.XML.(XML.Element)doc.I1=112233;