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:

ref="/element"
<element>form data</element>

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

ref="/element/@attribute"
<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. ...

Get XForms Essentials now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.