Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ensuring that one of three separate elements contains data

Status
Not open for further replies.

ikdevelop

Programmer
Jun 4, 2007
1
GB
Hi,
i have never had the need to write an XML Schema until now. and for the purposes of my web service i have got one alomst complete and the code to validate it. But, i have one problem which i am not sure how to solve.
A submitted XML doc (or string) to my web service must have at least one customer contact number, and i am not sure how to validate this.
At the moment my schema has the 3 possible contact numbers as separate elements. e.g.

<xs:element name="HomeNumber" type="xs:string"/>
<xs:element name="WorkNumber" type="xs:string"/>
<xs:element name="MobileNumber" type="xs:string"/>

but i am not sure how to say in the schema: 'one of this set of elements must contain data'.

If someone could help me out with how to best achieve this, i would be most appreciative.


Cheers
ik
 
if you want only one of the 3, try the choice element

Code:
<xs:element name="contactnumber">
  <xs:complexType>
    <xs:choice>
      <xs:element name="HomeNumber" type="xs:string"/>
      <xs:element name="WorkNumber" type="xs:string"/>
      <xs:element name="MobileNumber" type="xs:string"/>
    </xs:choice>
  </xs:complexType>
</xs:element>

K
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top