Question

I'm trying to find a way to write an XML 1.0 schema that avoids creating an untenable number permutations. I have 5 elements, A, B, C, D, and E. A must occur exactly once in the XML. B and C can occur 0 to infinity times in the XML. D and E can occur 1 to infinity times in the XML. A-E can occur in any order.

It's important to avoid writing out each possible sequence because if I need to add an element later the schema grows exponentially. Is there a way to do this?

Was it helpful?

Solution

Looks like it is impossible.

I have a book here: XML Schema: The W3C's Object-Oriented Descriptions for XML, which is probably the best book about XML schemas I've ever read (though rather complicated and not perfect one).

Here's what I see in that book (p. 236):

Situations describing unordered groups of optional elements that have the same number of maximum occurrences can be described using xs:choice or substitution groups, but other content models (such as groups unordered elements with arbitrary and different maximum numbers of occurrences) cannot be described with W3C XML Schema.

According to this, it looks like your A element (that must occur exactly once) spoils everything!

I believe the reason of that limitation is the following:

You want to avoid exponential permutations, right? But if such content models were allowed to describe in a simple way, it would take an exponential algorithm to validate XML against them!

I think, W3C just wanted to avoid such problems outright by forcing schema designers to avoid arbitrary content models.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top