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="testbjektType"
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 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="testbjektType"
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>