Hi guys,

I have built xsd for my xml.
Everything is working ok, but now I need to add support to the XML that a specific attribute will be unique.

The attribute that I need it to be unique is the "Id" attribute of the "Test" element, you can find it with the following code:

<xs:attribute ref="Id" use="required" />

here is my XSD:

<?xml version="1.0" encoding="utf-16"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="Interactions">
    <xs:complexType>
      <xs:sequence>
        <xs:element minOccurs="1" maxOccurs="unbounded" name="Test">
          <xs:complexType>
            <xs:sequence>
              <xs:element minOccurs="1" maxOccurs="unbounded" name="Interaction">
                <xs:complexType>
                  <xs:sequence>
                    <xs:choice minOccurs="1" maxOccurs="unbounded">
                      <xs:element maxOccurs="unbounded" name="div">
                        <xs:complexType mixed="true">
                          <xs:sequence minOccurs="0">
                            <xs:element maxOccurs="unbounded" name="span">
                              <xs:complexType>
                                <xs:simpleContent>
                                  <xs:extension base="xs:string">
                                    <xs:attribute ref="class" use="required" />
                                  </xs:extension>
                                </xs:simpleContent>
                              </xs:complexType>
                            </xs:element>
                          </xs:sequence>
                          <xs:attribute ref="class" use="required" />
                        </xs:complexType>
                      </xs:element>
                      <xs:element maxOccurs="unbounded" name="br">
                        <xs:complexType>
                          <xs:attribute ref="class" use="required" />
                        </xs:complexType>
                      </xs:element>
                    </xs:choice>
                  </xs:sequence>
                  <xs:attribute ref="Id" use="required" />
                  <xs:attribute ref="InPrinters" use="required" />
                  <xs:attribute ref="PicturePath" use="required" />
                  <xs:attribute ref="InteractionButtonId" use="required" />
                  <xs:attribute ref="InteractionIconId" use="required" />
                  <xs:attribute ref="TimeOut" use="optional" />
                </xs:complexType>
              </xs:element>
            </xs:sequence>
            <xs:attribute ref="Id" use="required" />
          </xs:complexType>
        </xs:element>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
  <xs:attribute name="InteractionButtonId">
    <xs:simpleType>
      <xs:restriction base="xs:string">
        <xs:enumeration value="InterBtnClrId" />
        <xs:enumeration value="InterBtnOkId" />
        <xs:enumeration value="InterBtnYnId" />
        <xs:enumeration value="InterBtnSkpId" />
        <xs:enumeration value="InterBtnVluId" />
        <xs:enumeration value="InterBtnYesId" />
        <xs:enumeration value="InterBtnNoId" />
        <xs:enumeration value="InterBtnNullId" />
      </xs:restriction>
    </xs:simpleType>
  </xs:attribute>
  <xs:attribute name="InteractionIconId">
    <xs:simpleType>
      <xs:restriction base="xs:string">
        <xs:enumeration value="InterIcnClrId" />
        <xs:enumeration value="InterIcnSnglId" />
        <xs:enumeration value="InterIcnMultlId" />
      </xs:restriction>
    </xs:simpleType>
  </xs:attribute>
  <xs:attribute name="InPrinters">
    <xs:simpleType>
      <xs:restriction base="xs:string">
        <xs:enumeration value="1" />
        <xs:enumeration value="2" />
      </xs:restriction>
    </xs:simpleType>
  </xs:attribute>
  <xs:attribute name="Id">
    <xs:simpleType>
      <xs:restriction base="xs:long" />
    </xs:simpleType>
  </xs:attribute>
  <xs:attribute name="PicturePath">
    <xs:simpleType>
      <xs:restriction base="xs:string" />
    </xs:simpleType>
  </xs:attribute>
  <xs:attribute name="class">
    <xs:simpleType>
      <xs:restriction base="xs:string">
        <xs:enumeration value="InteractionCrucial" />
        <xs:enumeration value="InteractionDefault" />
        <xs:enumeration value="InteractionNotDefault" />
        <xs:enumeration value="InteractionPlain" />
        <xs:enumeration value="InteractionHeader" />
        <xs:enumeration value="InteractionEmphasis" />
      </xs:restriction>
    </xs:simpleType>
  </xs:attribute>
  <xs:attribute name="TimeOut">
    <xs:simpleType>
      <xs:restriction base="xs:long" />
    </xs:simpleType>
  </xs:attribute>
</xs:schema>

Please help me, I need it ASAP and I cannot work it out maybe I do somthing wrong here.

Recommended Answers

All 2 Replies

Without seeing your XML file, I cannot give a precise answer. The element you need to use is <xsd:unique> and your schema modification should look something like this:

<xsd:unique  name= "uniqueId">
      <xsd:selector xpath="./yourxpath" />
      <xsd:field xpath="@Id"/>
    </xsd:unique>

fpmurphy thank you for your replay,

I know that i need to use the xsd:unique tag,
but i cannot work it out.
can't you look at my xsd and tell me where and how do i need to insert this tag.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.