Re: a small document about XML Schema <sequence> vs <all> constructs

You make some good points here and I'm not sure I can add much.

There are some cases where there clearly should be an order: in a table, the head comes before the body. (But why? Only because we are used to thinking of it that way. We could argue that this is purely a conventional way of presenting the table, and nothing to do with its semantics.)

I think there's actually a more general point about schema design: how much should one constrain things? Take the QT3 test suite. A typical test case looks like this:

   <test-case name="array-sort-019">
        <description>Atomize a map</description>
        <created by="Josh Spiegel" on="2015-08-10"/>
        <environment ref="array"/>
        <dependency type="spec" value="XQ31+"/>
        <test>array:sort([map{},1])</test>
        <result>
            <error code="FOTY0013"/>
        </result>
    </test-case>

The schema uses sequence rather than all. This document is often edited by hand and read by humans. The predictable ordering is helpful because the human reader knows where to find things at a glance. But it's also unhelpful, because the human editor can never remember whether dependency is supposed to come before or after environment. So from a usability perspective, it's a tough call, but one could probably say that imposing order makes things a little harder for authors and a little easier for readers. Note also that the human authors of this document have tended to be very consistent in the way attributes are ordered, even though the schema imposes no constraints. When, after a transformation, the dependency element reads  <dependency value="XQ31+" type="spec"/>, that really upsets the human reader. In fact, that's why I added a serialization property to Saxon to allow you to control attribute order on output.

If you're dealing with a vocabulary like GML that is never authored or read by humans, then these usability factors play no role, and it's even harder to find any good reason for deciding between sequence and all. There is certainly a good argument for saying that if the ordering carries no semantic information, there is no case for the schema to impose an order.

For software processing this document (specifically, a test driver or a reporting tool) the fixed order of elements doesn't really make much difference. Most of the time elements will be found using the XPath child::test or an equivalent, where any order would work.

So it's hard to say anything much about sequence vs all in such cases other than that, like so many things in the XML world, the design choice appears to be a matter of opinion - rather like coding styles in programming languages.

Michael Kay
Saxonica


> On 27 Jul 2016, at 04:02, Mukul Gandhi <gandhi.mukul@gmail.com> wrote:
> 
> Dear list,
>    I've been thinking on this topic for a while, and I thought I must write a technical document about it to share with like minded people. I've attempted to compare the XSD <sequence> and <all> constructs in this document. The link is below.
> 
> https://sites.google.com/site/gandhimukul/xml/sequenceVsAll_xsd.pdf <https://sites.google.com/site/gandhimukul/xml/sequenceVsAll_xsd.pdf>
> 
> If anyone on this list gets time to read this document, it'll be great. I'll happily respond to any mails on this via this list, and perhaps modify the referred document as per comments from anyone on this list.
> 
> 
> -- 
> Regards,
> Mukul Gandhi

Received on Wednesday, 27 July 2016 07:38:09 UTC