W3C home > Mailing lists > Public > xmlschema-dev@w3.org > July 2016

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

From: Michael Kay <mike@saxonica.com>
Date: Wed, 27 Jul 2016 08:37:34 +0100
Cc: "xmlschema-dev@w3.org" <xmlschema-dev@w3.org>
Message-Id: <D62F76E8-C26D-4003-B8CD-77F18AD854F2@saxonica.com>
To: Mukul Gandhi <gandhi.mukul@gmail.com>
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+"/>
            <error code="FOTY0013"/>

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

> 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

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 23:16:11 UTC