Monday, March 12, 2012

More concise XForms

Recently we made a proposal to the XForms working group to help reduce the size of XForms code.

The XForms syntax is XML-based. When designing an XML vocabulary, it's often hard to choose between using elements or attributes. XForms has historically leaned toward using more nested elements [1], which tend to add more markup (you need pointy brackets and closing tags), and more lines (as you tend to indent nested elements for readability).

For example, compare the following HTML:
<select>
    <option>French</option>
    <option>English</option>
</select>
with similar [2] XForms:
<select>
    <item>
        <label>French</label>
        <value>fr</value>
    </item>
    <item>
        <label>English</label>
        <value>en</value>
    </item>
</select>
You notice how <label> and <value> are defined as nested elements and influence a lot the size of the markup.

The programmer community lately seems to have spoken in favor of concision, witness languages like Ruby, CoffeeScript, and Scala, and we agree at Orbeon that concision is a great thing when it removes boilerplate and does not come at the cost of readability. So we propose to use more attributes nested text whenever possible. The XForms above becomes then:
<select>
    <item label="English">en</item>
    <item label="French">fr</tem>
</select>
That's just an illustration of the idea and the next step is to figure out the details, specifically which new attributes to support and where to allow nested text (like in the <item> value above). In addition, we propose to use attribute value templates (AVTs) to handle dynamic values and keep the concise syntax. For example, to retrieve the label from localized resources:
<input ref="name" label="{instance('resources')/name}"/>
The good news is that the working group has received the idea positively so far!

[1] One exception is the XForms for HTML Working Draft, which introduces a set of attributes for the purpose of integration with HTML.

[2] To be fair we are not exactly comparing apples and oranges here as HTML doesn't separate label and value for items. So XForms does a little more, but at the (unnecessary) cost of a lot of extra markup.

2 comments:

  1. This is an interesting proposal for select at least.

    I'm more perplex about CSS styling for input labels.

    -Alain

    ReplyDelete
  2. Alain,

    I think that whether you use a label child element or an attribute wouldn't necessarily change how you apply styling. The label attribute would generate an HTML element, and maybe XForms could suggest pseudo-elements for label, help, hint, and alert.

    -Erik

    ReplyDelete