Choosing the right data-type

XML or XForms or Orbeon data-types?

There is difference in how XML data types and XForms data types treat xml elements. Empty values are valid values in the eyes of XML types where as they are invalid for XForms types. This can be a major problem while dealing with required fields. 

xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xforms="http://www.w3.org/2002/xforms"
xmlns:xxforms="http://orbeon.org/oxf/xml/xforms"

Text nodes

Consider the following binding with XML data-type for a text node.

Example input

<instance name="instance">
  <startDate/>
</instance>

<xforms:bind nodeset="startDate" type="xs:date" required="true()"/>

Any non empty value is validated against date type and bind validity is determined. Empty value is treated as a valid value and hence the binding is valid.

<startDate></startDate>
VALID
<startDate>Rivetlogic</startDate>
INVALID
<startDate>01/12/2011</startDate>
VALID

If you use XForms data-type, empty values are treated as invalid along with the check for valid date value.

<xforms:bind nodeset="startDate" type="xforms:date" required="true()"/>

Check how empty values are marked invalid.

<startDate></startDate>
INVALID
<startDate>Rivetlogic</startDate>
INVALID
<startDate>01/12/2011</startDate>
VALID

XML nodes

What if you want to make a non text node required? Orbeon supports an extension type called "xxforms:xml". This is used for controls like node-selector where a multiple text nodes are grouped under the parent element which is a required field.

<instance name="instance">
  <images/>
</instance>

<xforms:bind nodeset="images" type="xxforms:xml" required="true()"/>

Empty element set is invalid.

<images>
<image src="path_to_image/myimage1.gif" width="40" height="40"/>
<image src="path_to_image/myimage2.gif" width="40" height="40"/>
</images>
VALID
<images></images>
INVALID

From the context of Crafter Studio it is recommended to use XForms data-types.

Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.