RE: XForms support for XML schema xsd:choice

Radu,
 
You need to use @relevant to turn off one of foo or bar. Then any controls
that are bound to those nodes will be 'enabled' or 'disabled' depending on
their value of relevant, and similarly submission will 'strip' the
non-relevant nodes. (Switch and case won't affect the model, so you need to
provide some other mechanism.)
 
The problem with this though is that XForms won't 'round-trip' this very
well--so if you save your choice of 'foo' and then later want to change it
to 'bar' there won't be a 'bar' element to choose. You server can put one in
though, before it sends it to the XForms processor, or you can add one in
the processor. (The 'how' is also a gray area...so I'll leave that for now!)
 
If things really are just a straight choice between two elements, and those
elements are very similar, then you might think of altering your schema so
that you only use one element, but have the type determined by an attribute.
XML Schema can cope with this fine, and you therefore don't need to swap
elements in and out, you just change the attribute value.

Regards,
 
Mark
 
 
Mark Birbeck
CEO
x-port.net Ltd.

e: Mark.Birbeck@x-port.net
t: +44 (0) 20 7689 9232
b: http://internet-apps.blogspot.com/
w: http://www.formsPlayer.com/

Download our XForms processor from
http://www.formsPlayer.com/ 

 


________________________________

	From: www-forms-request@w3.org [mailto:www-forms-request@w3.org] On
Behalf Of Radu Calinescu
	Sent: 02 May 2006 17:00
	To: www-forms@w3.org
	Subject: 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
<http://www.w3.org/2001/XMLSchema> " 
	            xmlns:my="http://example.com <http://example.com> "
	            targetNamespace="http://example.com <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 <http://example.com> " 
	              xmlns:xforms="http://www.w3.org/2002/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
<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 19:38:55 UTC