Jump to content

Multiple Elements In Any Order


Wylbur
 Share

Recommended Posts

Hi all;Let's see if I can get any responses to this one ...I have a schema for contact information,including alternate phone numbers (numbersother than a home phone number).I want the schema to reflect the fact that thenumbers (work and cell) can occur in any order,and in any number (including zero).Here is my test XML file:

<?xml version="1.0" encoding="UTF-8"?>  <all_names>    <fullpersoninfo>      <personinfo>        <firstname>Fred</firstname>        <middlename>Willis</middlename>        <lastname>Workman</lastname>      </personinfo>      <AddressRef>        <address>233 Pine Street</address>        <city>Austin</city>        <country>USA</country>        <home_phone>111</home_phone>      </AddressRef>        <alt_PhoneNumbers>          <cell>333</cell>          <work>222</work>        </alt_PhoneNumbers>    </fullpersoninfo>    <fullpersoninfo>      <personinfo>        <firstname>Fred</firstname>        <middlename>Willis</middlename>        <lastname>Walker</lastname>      </personinfo>      <AddressRef>        <address>233 Pine Street</address>        <city>Austin</city>        <country>USA</country>        <home_phone>4444</home_phone>      </AddressRef>        <alt_PhoneNumbers>          <cell>234</cell>        </alt_PhoneNumbers>    </fullpersoninfo>    <fullpersoninfo>      <personinfo>        <firstname>Joe</firstname>        <lastname>Smith</lastname>      </personinfo>      <AddressRef>        <address>1243 Long Road</address>        <city>Houston</city>        <country>USA</country>      </AddressRef>        <alt_PhoneNumbers>          <work>2222</work>          <cell>234</cell>          <cell>234</cell>        </alt_PhoneNumbers>    </fullpersoninfo>    <fullpersoninfo>      <personinfo>        <firstname>Janet</firstname>        <lastname>Burns</lastname>      </personinfo>      <AddressRef>        <address>1243 Short Road</address>        <city>Conroe</city>        <country>USA</country>      </AddressRef>    </fullpersoninfo>  </all_names>

This is my schema:

<?xml version="1.0"?><xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"><xs:complexType name="personinfo_type">  <xs:sequence>	<xs:element name="firstname" type="xs:string"/>	<xs:element name="middlename" type="xs:string"  minOccurs="0"/>	<xs:element name="lastname" type="xs:string"/>  </xs:sequence></xs:complexType><xs:complexType name="AddressRef_type">  <xs:sequence>		<xs:element name="address" type="xs:string"/>		<xs:element name="city" type="xs:string"/>		<xs:element name="country" type="xs:string"/>		<xs:element name="home_phone" type="xs:string" minOccurs="0" maxOccurs="unbounded"/>  </xs:sequence></xs:complexType><xs:complexType name="PhoneNumbers_type">	  <xs:all>		<xs:element name="work" type="xs:string" minOccurs="0" maxOccurs="1" />		<xs:element name="cell" type="xs:string" minOccurs="0" maxOccurs="1" />	  </xs:all></xs:complexType>	<xs:complexType  name="fullpersoninfo_type" >	  <xs:sequence>		<xs:element name="personinfo"  type="personinfo_type"/>		<xs:element name="AddressRef"  type="AddressRef_type" minOccurs="0" maxOccurs="unbounded"/>		<xs:element name="alt_PhoneNumbers"  type="PhoneNumbers_type" minOccurs="0"  maxOccurs="unbounded"/>	  </xs:sequence>	</xs:complexType><xs:element name="all_names"><xs:complexType>  <xs:sequence>	<xs:element name="fullpersoninfo" type="fullpersoninfo_type"  maxOccurs="unbounded" >	</xs:element>  </xs:sequence></xs:complexType></xs:element></xs:schema>

It fails to validate for Joe Smith.Does anyone have any ideas as to what I should try?Thanks!!!

Link to comment
Share on other sites

Before anyone suggests it, getting rid of "maxOccurs" will not solve the problem:

<xs:complexType name="PhoneNumbers_type">	  <xs:all>		<xs:element name="work" type="xs:string" minOccurs="0" />		<xs:element name="cell" type="xs:string" minOccurs="0" />	  </xs:all></xs:complexType>

Thanks!!!

Link to comment
Share on other sites

  • 1 year later...

I certainly hope you have found the answer to this someplace else considering the age of this post... The work around I have been using for this sort of issue is this:

<xs:complexType name="PhoneNumbers_type">  <xs:choice minOccurs="0" maxOccurs="2">    <xs:element name="work" type="xs:string" />    <xs:element name="cell" type="xs:string" />  </xs:choice></xs:complexType>

Edited by evanc
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...