XML Schema: Uniqueness constraints

silisEOalesEo

New Member
After hours of trying I'm still not able to get this simple example to do I want. The goal is very simple: A xml-Document with Notes is only valid if every \[code\]Node\[/code\] is assigned a unique \[code\]NoteID\[/code\].Here is my \[code\]Notes.xsd\[/code\]:\[code\]<?xml version="1.0" encoding="UTF-8"?><xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://xml.netbeans.org/schema/Notes" xmlns:tns="http://xml.netbeans.org/schema/Notes" elementFormDefault="qualified"> <xsd:element name="Notes"> <xsd:complexType> <xsd:sequence> <xsd:element name="Note" maxOccurs="unbounded"> <xsd:complexType> <xsd:sequence> <xsd:element name="NoteID" type="xsd:positiveInteger"/> <xsd:element name="Content" type="xsd:string"/> </xsd:sequence> </xsd:complexType> <xsd:unique name="newKey"> <xsd:selector xpath="."/> <xsd:field xpath="NoteID"/> </xsd:unique> </xsd:element> </xsd:sequence> </xsd:complexType> </xsd:element></xsd:schema>\[/code\]And \[code\]Notes.xml\[/code\]:\[code\]<?xml version="1.0" encoding="UTF-8"?><ns0:Notes xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:ns0='http://xml.netbeans.org/schema/Notes' xsi:schemaLocation='http://xml.netbeans.org/schema/Notes Notes.xsd'> <ns0:Note> <ns0:NoteID>1</ns0:NoteID> <ns0:Content>this</ns0:Content> </ns0:Note> <ns0:Note> <ns0:NoteID>1</ns0:NoteID> <ns0:Content>is a</ns0:Content> </ns0:Note> <ns0:Note> <ns0:NoteID>3</ns0:NoteID> <ns0:Content>test</ns0:Content> </ns0:Note></ns0:Notes>\[/code\]And I have no idea why this validates:\[code\]$ xmllint --noout -schema Notes.xsd Notes.xml Notes.xml validates\[/code\]
 
Back
Top