Daffodil speculatively parses the data. If data was successfully parsed,
it assumes what is parsed was correct and moves on.

So it first tries to parse an A, and that succeeds as "Hello". Since
maxOccurs=1 for the A element, it then moves on and tries to parse a B.
That succeeds as "world", and Daffodil moves onto trying a C, again
because maxOccurs=1. There is no more data left, so Daffodil says that
there is no C element, which is valid because minOccurs="0". The result
is that you get just an A and a B element.

If you wanted something else, you would have to tell Daffodil that the
data it assumed was an A/B was actually incorrect (i.e. the speculative
parse was wrong). Using a discriminator or assert is a typical way to do
that.

For example, maybe the B element cannot start with the letter 'w'. In
that case, you could define a discriminator like this:

<xs:element name="B" type="xs:string" minOccurs="0" ...>
  <xs:annotation>
    <xs:appinfo source="http://www.ogf.org/dfdl/";>
      <dfdl:discriminator test="{ fn:substring(., 1, 1) ne 'w' }" />
    </xs:appinfo>
  </xs:anotation>
</xs:element>

With this, Daffodil would speculatively parse "world" as a B, but then
would evaluate the discriminator, which would fail because it starts
with a 'w'. This would cause Daffodil to back up to before the B was
parsed, and try to speculatively parse the data as a C. That would
succeed since there's no discriminator, and you would get the second
infoset in your picture.

You could similarly put a discriminator on A to achieve the third result.

- Steve


On 10/3/19 1:48 PM, Costello, Roger L. wrote:
> Hello DFDL community,
> 
> Below I show two inputs into a schema with a sequence of three optional 
> elements. It seems reasonable to me that the XML could be any of the three 
> shown. I actually tested this and Daffodil outputs XML #1. Why? Why is that 
> the 
> output? Is there a way to get XML #2 and XML #3?  /Roger
> 

Reply via email to