Sergey Poberezovskiy wrote:
I have to specify that a person needs to have at least one out of three
phone elements:
<Phone type="home"/>,
<Phone type="work"/>,
<Phone type="mobile"/>,
The schema below defines a simple type enumerating the possible phone
types and then defines other elements.
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema
xmlns:xs="http://www.w3.org/2001/XMLSchema"
version="1.0">
<xs:simpleType name="phoneType">
<xs:restriction base="xs:string">
<xs:enumeration value="home" />
<xs:enumeration value="work" />
<xs:enumeration value="mobile" />
</xs:restriction>
</xs:simpleType>
<xs:element name="Persons">
<xs:complexType>
<xs:sequence>
<xs:element name="Person" type="PersonType"
maxOccurs="unbounded" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:complexType name="PersonType">
<xs:sequence>
<xs:element name="Name" type="xs:string" />
<xs:element name="Phone-Numbers">
<xs:complexType>
<xs:sequence>
<xs:element name="Phone" maxOccurs="10">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="type" type="phoneType" />
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:schema>
An example document is
<?xml version="1.0" encoding="UTF-8"?>
<Persons
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="test2005102401Xsd.x ml">
<Person>
<Name>Prename1 Surname1</Name>
<Phone-Numbers>
<Phone type="home">12345</Phone>
</Phone-Numbers>
</Person>
<Person>
<Name>Prename2 Surname2</Name>
<Phone-Numbers>
<Phone type="work">12345</Phone>
</Phone-Numbers>
</Person>
<Person>
<Name>Prename3 Surname3</Name>
<Phone-Numbers>
<Phone type="mobile">12345</Phone>
</Phone-Numbers>
</Person>
<Person>
<Name>Prename4 Surname4</Name>
<Phone-Numbers>
</Phone-Numbers>
</Person>
</Persons>
were a validating parser will flag the Phone-Numbers element in the last
Person element as an error as it needs to have at least one Phone child
element.
I don't know how many phone numbers you want to store for one person,
the schema above allows 1 to 10 as an example.
--
Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/