W3C home > Mailing lists > Public > xmlschema-dev@w3.org > February 2007

RE: xs:unique question

From: Stan Kitsis <skits@microsoft.com>
Date: Wed, 14 Feb 2007 10:26:10 -0800
To: Markus Gamperl <markus.gamperl@gmx.at>, "xmlschema-dev@w3.org" <xmlschema-dev@w3.org>
Message-ID: <03A576FA617C6544AEF9B925FB2B4E2A01F9145E3B@NA-EXMSG-C114.redmond.corp.microsoft.com>

Your schema needs to have a target namespace, a prefix for that target namespace and your xpath statements need to use that prefix.  So assuming you've defined a prefix for your target namespace to be tns, your uniqueness constraint should look like this:

<xs:unique name="uniquepreis">
  <xs:selector xpath="tns:preiszeile"/>
  <xs:field xpath="tns:zweig"/>
  <xs:field xpath="tns:herkunft"/>
</xs:unique>

-----Original Message-----
From: xmlschema-dev-request@w3.org [mailto:xmlschema-dev-request@w3.org] On Behalf Of Markus Gamperl
Sent: Wednesday, February 14, 2007 6:18 AM
To: xmlschema-dev@w3.org
Subject: xs:unique question


Hi.

I have defined the following complex type with a unique:

<xs:complexType name="root">
 <xs:sequence>
  <xs:element name="name" type="xs:string"/>
  <xs:element name="daten" nillable="true">
   <xs:complexType>
    <xs:sequence>
     <xs:element name="preiszeile">
       <xs:complexType>
        <xs:sequence maxOccurs="unbounded">
        <xs:element name="zweig" type="xs:integer"/>
        <xs:element name="herkunft" type="xs:integer"/>
        <xs:element name="anzahlen" type="xs:string"/>
     </xs:sequence>
    </xs:complexType>
   </xs:element>
  </xs:sequence>
 </xs:complexType>
 <xs:unique name="uniquepreis">
  <xs:selector xpath="preiszeile"/>
  <xs:field xpath="zweig"/>
  <xs:field xpath="herkunft"/>
 </xs:unique>
</xs:element>
</xs:sequence>
</xs:complexType>

example for a xml file:
<root>
 <name>76</name>
  <daten>
   <preiszeile>
        <zweig>11</zweig>
        <herkunft>0</herkunft>
        <anzahlen>test</anzahlen>
   </preiszeile>
   <preiszeile>
        <zweig>11</zweig>
        <herkunft>0</herkunft>
        <anzahlen>test</anzahlen>
   </preiszeile>
   <preiszeile>
        <zweig>11</zweig>
        <herkunft>0</herkunft>
        <anzahlen>test</anzahlen>
   </preiszeile>
   ...
  </daten>
</root>

I want a unique key over all zweig + herkunft elements.
Therefore I used xs:unique but it don't work...

Thanks
Markus
--
Der GMX SmartSurfer hilft bis zu 70% Ihrer Onlinekosten zu sparen!
Ideal für Modem und ISDN: http://www.gmx.net/de/go/smartsurfer
Received on Wednesday, 14 February 2007 18:26:30 UTC

This archive was generated by hypermail 2.3.1 : Wednesday, 7 January 2015 14:56:11 UTC