ITS Software Development and Distribution: XForms MODS Editor

updated May 9th, 2008

Overview
The Brown University Library has begun the implementation of our digital repository architecture. As such, we have developed a tool to collect basic metadata from users who wish to add content to the repository.

We follow the MODS schema and therefore a web-based MODS editor was built to create MODS XML records. These records are deposited into the eXist native XML database where they can be accessed via a REST API.

XForms technology was used to implement the web-based editor. More specifically the open source Orbeon Presentation Server was used as the XForms processor. This allows the editor to work in standard web browsers with no need for special client software or plugins.

The form is simple and clean, enforcing strict typing. An interactive user interface performs as-you-type validation. With Orbeon and XForms you can select optional data input for more complex metadata entry. An up-to-date error summary controls whether or not a user can submit the metadata. Once all required data and optional data is valid the user may then submit.

The interactive nature of the form is based on AJAX technology.

You can view the MODS editor demo and download the source code. If you have any questions contact Michael Park at Brown University.

How the XForms work
All XForms applications require an XForms processor to translate your XForms. It is very similar to how a browser interprets your HTML and JavaScript. Orbeon was used as the XForms processor and is at the core of the application. Orbeon is a robust open source server-side forms solution which can be implemented in two ways:

  • Using components provided by Orbeon Forms such as XML pipelines or
  • Simply use it as an XForms engine for your Java applications.

I chose to use it as an engine for my Java application. This is really quite simple to do:

  1. Place orbeon-xforms-filter.jar in WEB-INF/lib
  2. Add Orbeon settings to WEB-INF/web.xml
  3. Create a directory for the Orbeon XForms Engine to convert from
  4. Set crossContext to true and point docBase to your war file in the conf/server.xml file (or in an xml file with its own Context element in conf/Catalina/localhost)

The two most important complimenting XML technologies for XForms are XPath and XML schema. You use XPath to reference your XML data. While, XML schema allows you to define your own types and bind them to your input fields. This gives you the ability to validate user input data.

XForms follows the MVC architecture:

  • Model - define the structure of the MODS data
  • Controller - specify constraints and relationships between the MODS data
  • View - fields, buttons, and drop-down boxes, etc which reference the model

The model is comprised of XML instances. The 'mods-instance' is the actual XML data you are collecting to build a MODS record. There are other top-level MODS element instances which are used to dynamically build the final MODS record. For example, when a user wants to add a 'titleInfo' element its instance is used as a template and inserted into the 'mods-instance'. This is the case for all optional elements added.

Adding an element is done with an 'xforms:insert' via a trigger which reacts to an event (a button click). Likewise, an 'xforms:delete' will remove a particular element or attribute. In order to continually add more of an element you use the 'xforms:repeat' declaration. The repeat element has an id attribute which you reference from your 'xforms:insert'. The two work together to allow a user to keep adding a particular element.

XForms allows you to use 'xforms:bind" to bind to your XML data. You can use bind for validation(required, type, constraint), calculation, and visibility(read-only, relevant) of a particular XML node or attribute. These bindings are defined in the model along with the instances.

XForms controls are similar to HTML form elements: they include text fields, drop down lists, checkboxes, etc. In the body of your html you declare these controls and point them to your XML data using XPath.