Thank you Steve!

You've provided a workaround for optional choice: omit minOccurs="0" and add 
<xs:sequence/> within the choice.

Is there a workaround for optional elements in a choice?

/Roger

-----Original Message-----
From: Steve Lawrence <slawre...@apache.org> 
Sent: Friday, March 25, 2022 8:07 AM
To: users@daffodil.apache.org
Subject: [EXT] Re: Recommended changes to the DFDL language

One alternative for minOccurs on a choice is to have an empty branch:

   <xs:choice>
     <xs:element name="foo" ... />
     <xs:sequence />
   </xs:choice>

I admit that minOccurs="0" is a little more self documenting.

I think minOccurs also means something different if there are delimiters on the 
choice. For example, say we had these two snippets to implement an optional 
choice with a terminator:

   <xs:choice dfdl:terminator="X">
     <xs:element name="foo" ... />
     <xs:sequence />
   </xs:choice>

and

   <xs:choice dfdl:terminator="X" minOccurs="0">
     <xs:element name="foo" ... />
   </xs:choice>

In the former, if the X terminator doesn't exist, then it is a parse error. But 
in the later case with minOccurs, if the X terminator doesn't exist then it 
just means the choice doesn't exist.

So the semantics are a bit different. All that said, I don't think I've come 
across a case where we've absolutely needed minOccurs="0" on a choice, and not 
allowing it keeps DFDL simpler.

As to nillable complex other than %ES;, we have a ticket open to add this as an 
experimental feature, currently slated for the next release:

https://issues.apache.org/jira/browse/DAFFODIL-2636

On 3/25/22 7:46 AM, Roger L Costello wrote:
> Hi Folks,
> 
> I am converting 350 military data formats to DFDL.
> 
> Everyone of the 350 data formats has an optional choice:
> 
> <xs:choice minOccurs="0">
> 
> DFDL does not allow optional choice. Why?
> 
> I recommend changing the DFDL language to allow optional choice.
> 
> Everyone of the 350 data formats has branches of a choice that are optional:
> 
> <xs:choice>
>      <xs:element name="foo" minOccurs="0">
> 
> DFDL does not allow branches in a choice to be optional. Why?
> 
> I recommend changing the DFDL language to allow optional branches of a choice.
> 
> Many of the 350 data formats have an element with complexType that is 
> nillable and the nilValue is a hyphen.
> 
> DFDL does not allow an element with complexType to have a nilValue 
> other than %ES;
> 
> I recommend changing the DFDL language to allow elements with 
> complexType to have a nilValue other than %ES;
> 
> /Roger

Reply via email to