XForms support for XML schema xsd:choice

Hi,

I'm working on an XForms template for XML documents whose associated schemas contain xsd:choice declarations, e.g.,

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
            xmlns:my="http://example.com"
            targetNamespace="http://example.com"
            elementFormDefault="qualified">
  <xsd:element name="root">
    <xsd:complexType>
      <xsd:choice>
        <xsd:element name="foo" type="xsd:string" />
        <xsd:element name="bar" type="xsd:string" />
      </xsd:choice>      
    </xsd:complexType>
  </xsd:element>
</xsd:schema>

and finding it difficult to come up with an XForms model/UI combination that supports this use case. 

Although the XForms switch module (http://www.w3.org/TR/xforms/slice9.html#id148519) represents a suitable option for representing the choice in the UI, finding an appropriate model seems more difficult. Simply specifying a model such as:

<xforms:model xmlns:my="http://example.com" 
              xmlns:xforms="http://www.w3.org/2002/xforms" ...>
  <xforms:instance>
    <my:root>
      <my:foo />
      <my:bar />
    </my:root>
  </xforms:instance>
  ...
</xforms:model>

ensures that the UI can reference both my:foo and my:bar, but produces invalid XML documents that XForms-capable browsers rightfully reject. For instance, XSmiles (http://www.x-smiles.org/) reports "Invalid content starting with element 'my:bar'. No child element is expected at this point." when submission is attempted.

Notice that the XForms examples provided with the XForms 1.0 recommendation dated 14 March 2006 (http://www.w3.org/TR/xforms/sliceG.html) work around this issue by allowing the xsd:choice element to appear for any number of times in the document, i.e., 

<xsd:sequence minOccurs="0" maxOccurs="unbounded">
  <xsd:choice>
    ...
  </xsd:choice>
</xsd:sequence>

which makes an instance document such as the one suggested above valid, but does not address my specific use case.

IBM's XForms Generator (http://www.alphaworks.ibm.com/tech/xfg) comes with a number of "choice"-related samples that pair XML schemas with xsd:choice declarations and XML instance documents similar to the one presented above, and therefore suffer from the same limitation.

I would be grateful for any comments that might clarify this issue.

Radu

Received on Tuesday, 2 May 2006 18:54:33 UTC