tags:

views:

50

answers:

2

How can i define that the content of the emailaddress-element has to be unquie compared to all other emailaddresses entered inside the users-tag?

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"&gt;
<xs:element name="users">
    <xs:sequence>
        <xs:element name="user">
            <xs:element name="name" type="xs:string" />
            <xs:element name="emailaddress" type="xs:string" />
        </xs:element>
    </xs:sequence>
</xs:element>
A: 

You use the <xs:unique> tag as described here

Jim Garrison
+2  A: 

I think this is what you are after:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"&gt;
  <xs:element name="users">
    <xs:complexType>
      <xs:sequence maxOccurs="unbounded">
        <xs:element name="user">
          <xs:complexType>
            <xs:sequence>
              <xs:element name="name" type="xs:string"/>
              <xs:element name="emailaddress" type="xs:string"/>
            </xs:sequence>
          </xs:complexType>
        </xs:element>
      </xs:sequence>
    </xs:complexType>

    <!-- Make sure each user has a unique email address -->
    <xs:unique name="email-address-is-unique">
      <xs:selector xpath="user"/>
      <xs:field xpath="emailaddress"/>
    </xs:unique>

  </xs:element>
</xs:schema>

I also took the liberty of adding omitted elements from your original schema for completeness.

So the xpath attribute of the selector element defines the elements that are being used by the uniqueness constraint, then the field element(s) have xpaths which determine what needs to be unique across the selected elements.

Andy
Thanks... exactly what i needed!
DerKlops