XMLNSC: Element values and mixed content

The XMLNSC parser is a compact parser; therefore, an element with single content is parsed as a single syntax element. When an element has both child elements and some text, the text is called mixed content.

Element with simple content

The following XML fragment with a single content is parsed as a single syntax element:
<simpleElement>simpleValue</simpleElement>
The diagram shows the name, field type, and value of an element with simple content.
The value of this element can be queried with this ESQL:
SET val = FIELDVALUE(InputRoot.XMLNSC.(XMLNSC.Field)simpleElement);
To generate an element with simple content in the output:
SET OutputRoot.XMLNSC.(PCDataField)simpleElement VALUE = 'simpleValue';  
Note that XMLNSC.Field is used when querying the message tree, but XMLNSC.PCDataField is specified when constructing the output message. XMLNSC.PCDataField can be used to query the message tree; however, that would not work if the input message used a CData section, as shown in the following example:
<simpleElement><![CDATA[simpleValue]]></simpleElement>

Element with mixed content

If an element has child elements, it is typically a 'folder', and does not have a value. When an element has both child elements and some text, the text is called 'mixed content'.
<element>mixed1<child>simpleValue</child>mixed2</element>
By default, mixed content is discarded because it is typically just formatting white space and has no business meaning. Mixed content can be preserved if you select the Retain mixed content check box on the Parser Options page of the node properties.

If mixed content is being preserved, the XMLNSC parser creates a Value child element for each distinct item of mixed content.

The diagram shows child elements that have been created for mixed content.
The mixed content can be queried with this ESQL:
SET mixed1 = FIELDVALUE(InputRoot.XMLNSC.(element).*[1];
The ESQL to construct the above XML fragment is:
CREATE ref REFERENCE TO OutputRoot.XMLNSC.element; 
CREATE FIRSTCHILD OF ref TYPE XMLNSC.PCDataValue VALUE 'mixed1'; 
CREATE LASTCHILD OF ref NAME 'child' TYPE XMLNSC.PCDataField  VALUE 'simpleValue';  
CREATE LASTSTCHILD OF ref TYPE XMLNSC.PCDataValue VALUE 'mixed2';
The following ESQL enables the Retain mixed content option:
DECLARE X BLOB; 
-- assume that X contains an XML document 
CREATE LASTCHILD OF OutputRoot
    PARSE(X OPTIONS XMLNSC.MixedContentRetainAll); 

Element containing a CData section

A CData section is an XML notation that allows XML markup characters to be included in the content of an element.

The following two XML fragments are identical in their meaning:
<simpleElement>simpleValue</simpleElement>
<simpleElement><![CDATA[simpleValue]]></simpleElement>
If the CData section is the only text content, the XMLNSC parser remembers that the input document contained a CData section by setting the field type to XMLNSC.CDataField instead of XMLNSC.PCDataField.

If the CData section is not the only text content, it is created as a child value element, with other child value elements representing the remaining text content. The following is an example of this:

<simpleElement><![CDATA[CDataValue]]>normalText</simpleElement>
The diagram shows that a CDataValue child element has been created.

See XMLNSC: Working with CData for more information about the correct use of CData in XML documents.