You are reading O'Reilly XForms Essentials by Micah Dubinko. (What is this?) - Buy XForms Essentials Online

Interaction with Instance Data

Form controls transform the user input into either a string of characters (called simpleContent) or child elements. In XML, character data can occur in many ways, including attributes, element content, comments, processing instructions, and so on. For the most part, XForms interacts intuitively with XML.

When bound to an attribute or an element with text-only content, the mapping is straightforward: it uses the attribute value or the text child node of the attribute:

<element>form data</element>

ref="/element/text(  )"
<element>form data</element> (equivalent to direct element reference)

<element attribute="form data"/>

For these purposes, an empty element (<element/>) is treated as a zero-length string.

Comments and processing instructions are straightforward: don't do it. To encourage authors to keep important form data in elements and attributes, XForms leaves the binding undefined for comments and processing instructions (if these exist in the initial instance data, they will be passed through unchanged, so this admonition applies only to their use in storing form data).

It gets more complicated when mixed content enters the picture. When confronted with this situation, a new text node will be created as the first child of the target element, which usually isn't the intended effect. Thus, mixed content isn't supported in off-the-shelf XForms 1.0, though some proposed extensions enable the common case of XHTML.

Generally, elements that contain other elements or a combination of text and elements shouldn't be used as an endpoint for form data.