W3C home > Mailing lists > Public > xmlschema-dev@w3.org > April 2003

Re: Atleast one element should be present in ComplexType.

From: Henry S. Thompson <ht@cogsci.ed.ac.uk>
Date: 02 Apr 2003 09:38:38 +0100
To: "Avula, Raj" <ravula@firstam.com>
Cc: "'xmlschema-dev@w3.org'" <xmlschema-dev@w3.org>
Message-ID: <f5bwuid47ld.fsf@erasmus.inf.ed.ac.uk>

"Avula, Raj" <ravula@firstam.com> writes:

> 	I have a complexType with two element children and I need to make
> sure that atleast one of that should be present.
> Here is the sample.
> 
> 	<xs:element name="REQUEST">
> 		<xs:complexType>
> 			<xs:sequence>
> 				<xs:element ref="OPTION" minOccurs="0"
> maxOccurs="unbounded"/>
> 				<xs:element ref="DATA" minOccurs="0"/>
> 			</xs:sequence>
> 		</xs:complexType>
> 	</xs:element>
> 
> In the above example, I need to make sure that atleast on among OPTION, DATA
> should be present.

There's no general way to do this, but in a simple case such as this
you can do it by hand:

  (option+,data?|data)

 <xs:element name="REQUEST">
  <xs:complexType>
   <xs:choice>
    <xs:sequence>
     <xs:element ref="OPTION" minOccurs="1" maxOccurs="unbounded"/>
     <xs:element ref="DATA" minOccurs="0"/>
    </xs:sequence>
     <xs:element ref="DATA"/>
   </xs:choice>
  </xs:complexType>
 </xs:element>

ht
-- 
  Henry S. Thompson, HCRC Language Technology Group, University of Edinburgh
                      Half-time member of W3C Team
     2 Buccleuch Place, Edinburgh EH8 9LW, SCOTLAND -- (44) 131 650-4440
     Fax: (44) 131 650-4587, e-mail: ht@cogsci.ed.ac.uk
       URL: http://www.ltg.ed.ac.uk/~ht/
 [mail really from me _always_ has this .sig -- mail without it is forged spam]
Received on Wednesday, 2 April 2003 03:38:40 GMT

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