W3C home > Mailing lists > Public > xmlschema-dev@w3.org > September 2002

Re: Help: Is this possible at all with XML schema?

From: Eddie Robertsson <erobertsson@allette.com.au>
Date: Thu, 26 Sep 2002 14:06:10 +1000
Message-ID: <3D9287B2.3030801@allette.com.au>
To: xin wang <xvwang@yahoo.com>
CC: xmlschema-dev@w3.org

Hi Victoria,

>I need a schema for the following XML:
>(In "Test", all of the elements (name, description,case) are not in any particular order. "name" and "description" appear 0 or 1 time. "case" appears 0 to unbounded times.)
>
><Test>
>  <name>my test</name>
>  <description>need help</description>
>  <case ref="case1"/>
>  <case ref="case2"/>
></Test>
>
><Case id="case1"/>
><Case id="case2"/>
>
>Is this possible at all?
>
No, you can't get exactly this.

>The closest thing that I do know how to model is the following:
>
><Test>
>  <name>my test</name>
>  <description>need help</description>
>  <set_of_cases>
>    <case ref="case1"/>
>    <case ref="case2"/>
>  </set_of_cases>
></Test>
><Case id="case1"/>
><Case id="case2"/>
>
>schema:
>
><xs:complexType name="Test">
>  <xs:all>
>    <xs:element name="name"/>
>    <xs:element name="description"/>
>    <xs:element ref="set_of_cases"/>
>  </xs:all>
></xs:complexType>
>
><xs:element name="set_of_cases">
>  <xs:complexType>
>    <xs:sequence>
>      <xs:element name="case" minOccurs="1"
>maxOccurs="unbounded">
>         <xs:complexType>
>            <xs:attribute name="ref"/>
>          </xs:complexType>
>       </xs:element>
>     </xs:sequence>
>   </xs:complexType>
></xs:element>
>  
>
Yep, that's as close as you can get by using W3C XML Schema alone. 
However, if you have the ability add Schematron rules to your schema 
then you can express exactly this content model. See [1] for more 
information and there is one example that does exactly what you're 
looking for [2].

Cheers,
/Eddie

[1] http://www.topologi.com/public/Schtrn_XSD/Paper.html
[2] 
http://www.topologi.com/public/Schtrn_XSD/Paper.html#2Interleaving_of_elements

>Thank you very much.
>
>victoria
>
>__________________________________________________
>Do you Yahoo!?
>New DSL Internet Access from SBC & Yahoo!
>http://sbc.yahoo.com
>
>  
>
Received on Thursday, 26 September 2002 00:02:27 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Tuesday, 11 January 2011 00:14:34 GMT