Question about form design with optional elements

XFormers,

What suggestions do you have for an elegant way to design XForms for editing XML instance data when many elements of that data can be optional?  In particular, an optional element should not be present in the final data if it was not given a value during an editing session.

Our application uses XForms for editing XML fragments in this kind of general situation: where many of the elements are optional.  For example, a template for such a fragment might look like this:

  <X>
    <a/>
    <b/>
    <c/>
  </X>

where the elements named `a`, `b`, and `c` are each optional within their parent.  If a user then provides values for `a` and `c`, the final data should look like this:

  <X>
    <a>value for a</a>
    <c>value for c</a>
  </X>

One approach is to start with a minimal base instance,

  <xf:instance id="minimal-base"><X/></xf:instance>

and then explicitly add to this minimal instance, drawing elements (using `xf:insert`) from an instance that stores templates, such as:

  <xf:instance id="templates">
    <templates><a/><b/><c/></templates>
  </xf:instance>

This, however, requires that the user perform two actions whenever she wants to add a value.  First she must cause the desired node to be inserted, and then she must actually provide its value.

Another approach is to start with a maximal base instance,

  <xf:instance id="maximal-base">
    <X>
      <a/>
      <b/>
      <c/>
    </X>
  </xf:instance>

and then remove any of the optional elements that are "empty" when the instance is submitted.  This approach requires expanding the starting state of the instance data to its maximal form before editing, and then pruning it back again after editing.  Our experiments have performed both expanding and pruning on the server side, although it may be possible to do these operations using XForms itself.  For example, pruning could be implemented using some creative "relevance" MIPs.  Having all this extra machinery for simply dealing with optional elements feels crude, however, and in our experience is defect-prone.

What do you think of these two approaches?  Do you have any other suggestions?  Thank you for any insight you may provide!

Take care,

    John L. Clark


P Please consider the environment before printing this e-mail

Cleveland Clinic is ranked one of the top hospitals
in America by U.S. News & World Report (2007).  
Visit us online at http://www.clevelandclinic.org for
a complete listing of our services, staff and
locations.


Confidentiality Note:  This message is intended for use
only by the individual or entity to which it is addressed
and may contain information that is privileged,
confidential, and exempt from disclosure under applicable
law.  If the reader of this message is not the intended
recipient or the employee or agent responsible for
delivering the message to the intended recipient, you are
hereby notified that any dissemination, distribution or
copying of this communication is strictly prohibited.  If
you have received this communication in error,  please
contact the sender immediately and destroy the material in
its entirety, whether electronic or hard copy.  Thank you.

Received on Wednesday, 16 July 2008 20:12:40 UTC