Validator ignores my <xs:unique>

U

Ulf Heyder

Hello everyone,

I want to add a unique constraint to a XSD I created.

After I modified validation (XMLSpy, Castor-0.9.5 marshaller) of my
example (see below) against the XSD (also see below) doesn't lead to
any errors/warnings.

I tried several different combinations for the <xs:selector> and
<xs:field>.

Does anyone have an idea what I do wrong?

Thanks, Ulf

--- UniqueTest.xsd ---------------------------------

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema
targetNamespace="http://www.test.de/test"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:test="http://www.test.de/test" elementFormDefault="qualified"
attributeFormDefault="unqualified">
<!-- -->
<xs:element name="liste">
<xs:complexType>
<xs:sequence>
<xs:element name="objekt" type="test:eek:bjektType"
maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
<xs:unique name="unq">
<xs:selector xpath="liste"/>
<xs:field xpath="objekt/@nummer"/>
</xs:unique>
</xs:element>
<!-- -->
<xs:complexType name="objektType">
<xs:sequence>
<xs:element name="beschreibung" type="xs:string"/>
<xs:element name="typ" type="xs:string"/>
</xs:sequence>
<xs:attribute name="nummer" use="required">
<xs:simpleType>
<xs:restriction base="xs:integer">
<xs:minInclusive value="1"/>
<xs:maxInclusive value="9999"/>
</xs:restriction>
</xs:simpleType>
</xs:attribute>
</xs:complexType>
</xs:schema>

--- UniqueTest.xml ---------------------------------

<?xml version="1.0" encoding="UTF-8"?>
<!-- edited with XMLSPY v5 U (http://www.xmlspy.com) by DAVID ibR (ibR
Ges. für Geoinformation mbH) -->
<liste
xmlns="http://www.test.de/test"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.test.de/test UniqueTest.xsd">
<objekt nummer="123">
<beschreibung>blubber</beschreibung>
<typ>wenigschlimm</typ>
</objekt>
<objekt nummer="123">
<beschreibung>bla</beschreibung>
<typ>schlimm</typ>
</objekt>
<objekt nummer="234">
<beschreibung>blubb</beschreibung>
<typ>sehrschlimm</typ>
</objekt>
<objekt nummer="345">
<beschreibung>blubbidubb</beschreibung>
<typ>schlimm</typ>
</objekt>
</liste>
 
I

Itay Zandbank

Hello everyone,
I want to add a unique constraint to a XSD I created.

Does anyone have an idea what I do wrong?

You need to fully qualify your XPath expression, like so:

<xs:unique name="unq">
<xs:selector xpath="test:liste"/>
<xs:field xpath="test:eek:bjekt/@nummer"/>
</xs:unique>

Hope this helps.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,818
Latest member
SapanaCarpetStudio

Latest Threads

Top