how do I use the unique constraint in schema

admin

Administrator
Staff member
instance file
<?xml version="1.0" encoding="iso-8859-1"?>
<students
xmlns="http://www.mydom.org/students"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.mydom.org/students students.xsd">

<student Id="s4031">
<gradYear>2009</gradYear>
</student>

<student Id="s4031">
<gradYear>2009</gradYear>
</student>

</students>



students.xsd
<?xml version="1.0" encoding="iso-8859-1"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema"
xmlns:ourStudents="http://www.mydom.org/students"
targetNamespace="http://www.mydom.org/students"
elementFormDefault="qualified">

<element name="students">
<complexType>
<sequence minOccurs="0" maxOccurs="unbounded">
<element name="student">
<complexType>
<sequence>
<element name="gradYear" type="string" />
</sequence>
<attribute name="Id" type="NCName" />
</complexType>
</element>
</sequence>
</complexType>
<unique name="u_student">
<selector xpath="./student" />
<field xpath="@Id" />
</unique>
</element>

</schema>

I really expect my validator (Topologi Schematron Validator) to kick an error due to the duplicate ID values of "s4031" but it doesn't, it reports students.xml as being error free. Please don't with "<attribute name="Id" type="ID" />" I know this will acomplish uniqueness, I'm trying to learn how to use the unique element. Can anyone tell me why this won't report as a duplicate Id as I have it configured. One more question: can you also give me the selector and field xpath values if I decide to change the Id from an attribute of the student element to a child element of the student element and still maintain uniqueness?
 
Back
Top