The following schema will do what you need. It defines a sequence with
three occurrences of param element and then uses a uniqueness constraint to
enforce unique attributes.
<?xml version="1.0" encoding="utf-8" ?>
<xs:schema targetNamespace="http://myschemas/foo"
elementFormDefault="qualified"
xmlns:foo="http://myschemas/foo"
xmlns="http://myschemas/foo"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:complexType name="paramType">
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="ptype" type="paramAttrType" use="required" />
</xs:extension>
</xs:simpleContent>
</xs:complexType>
<xs:simpleType name="paramAttrType">
<xs:restriction base="xs:string">
<xs:enumeration value="init"/>
<xs:enumeration value="process"/>
<xs:enumeration value="kill"/>
</xs:restriction>
</xs:simpleType>
<xs:complexType name="paramsType">
<xs:sequence>
<xs:element name="param" minOccurs="3" maxOccurs="3"
type="paramType"/>
</xs:sequence>
</xs:complexType>
<xs:element name="params" type="paramsType">
<xs:unique name="uniqueParams">
<xs:selector xpath="foo:param"/>
<xs:field xpath="@ptype"/>
</xs:unique>
</xs:element>
</xs:schema>
--
Stan Kitsis
Program Manager, XML Technologies
Microsoft Corporation
This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm
<mo********@gmail.com> wrote in message
news:11*********************@f14g2000cwb.googlegro ups.com...
Hello,
I have a document like this:
<parameters>
<param ptype="init">somedata</param>
<param ptype="process">moredata</param>
<param ptype="kill">alsodata</param>
</parameters>
<param> has the following definition in my XSD:
<xs:complexType name="param">
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="ptype" type="xs:string" use="required" />
</xs:extension
</xs:simpleContent>
</xs:complexType>
The question I have is: I want to require <parameters> elements to
contain exactly 3 <param> elements, and furthermore, to require one
element with the attribute ptype="init", one element with
ptype="process", and another with ptype="kill".
So, for example I want to invalidate this document:
<parameters>
<param ptype="init">somedata</param>
<param ptype="kill">alsodata</param>
</parameters>
because it is missing an element with ptype="process".
I am somewhat new to XSD. Could someone help me?