Re: XML Schema Question

Just a little sideremark...

We shouldn't be offering these kind of solutions to novices in XMLSchema 
or people who are in the process of (re)defining their schemas.

There is a very good reason why ordering is preferred to non-ordering 
and it is the "XML Schema"-way to do things.
All of the solutions offered here are overcomplicating implementations 
and confusing users, pushing them to other validation technologies or 
wrecking the validation performance.

XMLSchema can be clean and simple and that's how we should guide 
potential users...

What do you people think?

Mik



Michael Kay wrote:

>>This is the most frequent of FAQs. It can't be done in XML Schema.
>>    
>>
>
>Actually, I think someone did discover a way of doing it. You can use a
>choice as in (2) below, and then use a uniqueness constraint to ensure there
>is only one father and only one mother. Under the element declaration for
>family, you add:
>
><xs:unique name="one-father">
>  <xs:selector xpath="."/>
>  <xs:field xpath="father"/>
></xs:unique>
>
>This will cause a validation error if a the xs:field expression selects more
>than one node, that is, if a family has more than one father.
>
>Michael Kay
>Saxonica Limited
>www.saxonica.com
>
>  
>
>>Your options are:
>>
>>1. Constrain the order as in your current schema, and use a simple
>>transformation to transform the any-order documents into the
>>constrained-order documents, which you can then validate.
>>
>>2. Use a content model with no constraints on occurrence, as in:
>>
>>  <xs:choice minOccurs="0" maxOccurs="unbounded">
>>    <xs:element ref="father" />
>>    <xs:element ref="mother" />
>>    <xs:element ref="son" />
>>    <xs:element ref="daughter" />
>>    <xs:element ref="pet" />
>>  </xs:choice>
>>
>>and add supplementary Schematron rules to constrain the occurrence of
>>each of the elements. The Schematron rules can be processed in a
>>separate step.
>>
>>3. Switch to using RELAX NG, where you can do:
>>
>>  <interleave>
>>    <optional><ref name="father" /></optional>
>>    <optional><ref name="mother" /></optional>
>>    <zeroOrMore><ref name="son" /></zeroOrMore>
>>    <zeroOrMore><ref name="daughter" /></zeroOrMore>
>>    <zeroOrMore><ref name="pet" /></zeroOrMore>
>>  </interleave>
>>
>>or, in compact syntax:
>>
>>  father? & mother? & son* & daughter* & pet*
>>
>>Cheers,
>>
>>Jeni
>>
>>---
>>Jeni Tennison
>>http://www.jenitennison.com/
>>
>>
>>
>>    
>>
>
>
>  
>

Received on Monday, 23 August 2004 14:17:58 UTC