Overview for Developers

Libraries

Enketo maintains 4 libraries (Core, Transformer, XPath Evaluator, Validate) that can be used to build an Enketo-powered application. The illustration below shows how 3 of these libraries are used as building blocks of one such application: Enketo Express.

Enketo Express

  • communication with OpenRosa server
  • persistent storage in browser
  • offline launch in browser
client

Enketo Core

  • form rendering
  • form logic
  • form API

OpenRosa XPath Evaluator

  • XPath evaluation
server

Enketo Transformer

  • XSL transformation of XForm
  • markdown processsing
  • language directionality
  • media/data resource URI resolution

These libraries are divided in a logical way so they can be used for light-weight mobile hybrid applications, as well as web applications. They don't use opinionated JS frameworks either to provide further flexibility and sustainability.

Enketo's XForm validator can be seen in action side-by-side with ODK Validate at validate.enketo.org.

Transformation

Enketo's form engine (Enketo Core) does not read XForms directly. It works with the result of a transformation of an XForm into a JSON object containing a form HTML string and a model XML string. The illustration below gives a high-level overview of this transformation.

XForm instances
<model>
  <instance>
    <data>
      <node/>
      <resp/>
    </data>
  </instance>
  <instance id="countries"/>
  ...
</model>
XForm binds
<bind 
  nodeset="/data/node" 
  relevant="/data/resp = 'a'"
  constraint=". > 6"
  type="integer"
/>
XForm body
<input 
  ref="/data/node"
  appearance="distress"
>
  <label>Enter Number</label>
</input>
XML instances
<model>
  <instance>
    <data>
      <node/>
      <resp/>
    </data>
  </instance>
  <instance id="countries"/>
  ...
</model>
HTML form
<form class="or">
  <label 
    class="...-distress"
  >
    <span>Enter Number</span>
    <input
      type="number"
      name="/data/node"
      data-relevant="/data/resp= 'a'"
      data-constraint=". > 6"
      data-type-xml="integer"
    />
  </label>
</form>

The transformation uses XSL and could theoretically be performed by any XSL Transformer in any language. It's been confirmed to work in PHP and NodeJS.