Jump to content

Setting unique element restriction


Recommended Posts

Here is my schema, what I'm unable to do is set unique restrictions on the title element.

<?xml version="1.0" encoding="ISO-8859-1"?><xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">	<xs:element name="departments">		<xs:complexType>			<xs:sequence>				<xs:element ref="department" minOccurs="1" maxOccurs="unbounded"/>			</xs:sequence>		</xs:complexType>	</xs:element>	<xs:element name="department">		<xs:complexType>			<xs:sequence>				<xs:element ref="title" minOccurs="1" maxOccurs="1"/>				<xs:element ref="subdepartment" minOccurs="1" maxOccurs="unbounded"/>			</xs:sequence>		</xs:complexType>	</xs:element>	<xs:element name="title">		<xs:simpleType>			<xs:restriction base="xs:string"/>		</xs:simpleType>	</xs:element>	<xs:element name="subdepartment">		<xs:simpleType>			<xs:restriction base="xs:string"/>		</xs:simpleType>	</xs:element></xs:schema>

What I'm trying is this within the title element tag, XMLSpy accepts it as valid but the restriction does not work if I test duplicate titles in my XML.

<xs:unique name="testUnique">	<xs:selector xpath="department"/>	<xs:field xpath="title"/></xs:unique>

Please help!

Edited by tombliboo
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

  • Create New...