Re: RE: unique question

Hi Michael!

Thanks for your suggestion - I totally agree with you.

This is my complex type:

<xs:complexType name="root">
 <xs:sequence>
  <xs:element name="name" type="xs:string" fixed="76"/>
  <xs:element name="daten" nillable="true">
   <xs:complexType>
    <xs:sequence>
     <xs:element name="preiszeile" maxOccurs="unbounded">
      <xs:complexType>
	<xs:sequence>
		<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>

A correct example for a xml fragment:

<root>
 <name>76</name>
  <daten>
   <preiszeile>
     <zweig>11</zweig>
     <herkunft>0</herkunft>
     <anzahlen>test</anzahlen>
   </preiszeile>
   <preiszeile>
     <zweig>11</zweig>
     <herkunft>1</herkunft>
     <anzahlen>test</anzahlen>
   </preiszeile>
   <preiszeile>
     <zweig>12</zweig>
     <herkunft>0</herkunft>
     <anzahlen>test</anzahlen>
   </preiszeile>
    ...
  </daten>
</root>

Problem description:
The "daten" element can contain unbounded "preiszeile" elements. Every "preiszeile" element must contain one "zweig", "herkunft" and "anzahlen" element.
I want to avoid that there are duplicated values within "zweig" and "herkunft" in combination - like a classic unique key in a database.

A wrong xml file fragment: In the first and second "preiszeile" have the elements "zweig" and "herkunft" the same value - I want to avoid this with an unique constraint

<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>12</zweig>
     <herkunft>0</herkunft>
     <anzahlen>test</anzahlen>
   </preiszeile>
    ...
  </daten>
</root>

Was my explanation clear - do you understand my problem?

Thanks
Markus



Betreff: RE: unique question

> Your schema allows a daten to contain only one preiszeile, and a
> preiszeile
> to contain any number of zweig/herkunft/anzahlen triplets. But your
> instance
> data shows a daten containing many preiszeilen, and each preiszeile
> containing just one zweig/herkunft/anzahlen triplet. So quite apart from
> your uniqueness constraint, your schema and instance don't seem to match.
> 
> Michael Kay
> http://www.saxonica.com/ 
> 

-- 
"Feel free" - 5 GB Mailbox, 50 FreeSMS/Monat ...
Jetzt GMX ProMail testen: www.gmx.net/de/go/mailfooter/promail-out

Received on Wednesday, 14 February 2007 19:18:58 UTC