Saturday, April 30, 2011

XML Schema: facets constraining the cardinality of simpleType->list

I thought I should write a little clarification of a point I mentioned in my blog post,

I seem to have suggested in the above cited post, that XML Schema 1.1 assertions are probably necessary to impose restrictions on cardinality of an XML Schema simpleType list instance. But this fact doesn't appear to be true, after I realized this reading the XML Schema spec lately; which allows the following constraining facets on XML Schema simpleType's with variety list:
<xs:length ../>
<xs:minLength ../>
<xs:maxLength ../>

(ref, which says, "If {variety} is list, then the applicable facets are assertions, length, minLength, maxLength, pattern, enumeration, and whiteSpace")

These constraining facets [1], on simpleType with variety list were available in XML Schema 1.0 too.

These facets [1] may serve the design purpose (and should probably be even efficient than using assertions, since assertions require compiling the XPath expressions in their "test" attribute's, and to build quite a bit of context information for XPath expression evaluation) I had mentioned in the above cited post.

Also to mention, that an assertion facet for simpleType with variety list, could be found useful for other purposes (i.e they are not without purpose!), for example as follows:

<xs:assertion test="count($value) mod 2 = 0"/>

(the list instance must have even number of items)

Thanks for reading this post!