Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. XML / XSL
  4. Specifying unqiueness of an attribute in xsd.

Specifying unqiueness of an attribute in xsd.

Scheduled Pinned Locked Moved XML / XSL
xmldatabasecomquestionannouncement
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    Comp_Users
    wrote on last edited by
    #1

    Hi All, I have an simple xml file for which I generated an xsd file using Altova XMLSpy tool. As I wanted the end user who makes the xml entry to enter an unique ID which is an attribute of one of the elements. I modified the generated xsd file to accomodate this rule by including "xs:unique" node and entered valid values(i believe)but to no avail. Below is my xml file.

    <?xml version="1.0"?>
    <wwdfdb:DDB xmlns:wwdfdb="http://www.xybec.com/ns/wwdfdb" version="1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.xybec.com/ns/wwdfdb Sample.xsd">
    wwdfdb:MyList
    <wwdfdb:Num id="3020">
    wwdfdb:Ver1.0.0.1</wwdfdb:Ver>
    wwdfdb:StatusInUse</wwdfdb:Status>
    </wwdfdb:Num>
    <wwdfdb:Num id="3021">
    wwdfdb:Ver1.0.0.1</wwdfdb:Ver>
    wwdfdb:StatusInUse</wwdfdb:Status>
    </wwdfdb:Num>
    </wwdfdb:MyList>
    </wwdfdb:DDB>

    Below is the xsd file for the xml file.

    <?xml version="1.0" encoding="UTF-8"?>
    <!--W3C Schema generated by XMLSpy v2009 sp1 (http://www.altova.com)-->
    <xs:schema xmlns="http://www.xybec.com/ns/wwdfdb" xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.xybec.com/ns/wwdfdb">
    <xs:element name="Ver">
    xs:simpleType
    <xs:restriction base="xs:string">
    <xs:enumeration value="1.0.0.1"/>
    </xs:restriction>
    </xs:simpleType>
    </xs:element>
    <xs:element name="Status">
    xs:simpleType
    <xs:restriction base="xs:string">
    <xs:enumeration value="InUse"/>
    </xs:restriction>
    </xs:simpleType>
    </xs:element>
    <xs:element name="Num">
    xs:complexType
    xs:sequence
    <xs:element ref="Ver"/>
    <xs:element ref="Status"/>
    </xs:sequence>
    <xs:attribute name="id" use="required">
    xs:simpleType
    <xs:restriction base="xs:short">
    <!--<xs:enumeration value="3020"/>
    <xs:enumeration value="3021"/>-->
    </xs:restriction>
    </xs:simpleType>
    </xs:attribute>
    </xs:complexType>
    </xs:element>
    <xs:element name="MyList">
    xs:complexType
    xs:sequence
    <xs:element ref="Num" maxOccurs="unbounded"/>
    </xs:sequence>
    </xs:complexType>
    <!--added below lines to achieve uniqueness for at

    S 1 Reply Last reply
    0
    • C Comp_Users

      Hi All, I have an simple xml file for which I generated an xsd file using Altova XMLSpy tool. As I wanted the end user who makes the xml entry to enter an unique ID which is an attribute of one of the elements. I modified the generated xsd file to accomodate this rule by including "xs:unique" node and entered valid values(i believe)but to no avail. Below is my xml file.

      <?xml version="1.0"?>
      <wwdfdb:DDB xmlns:wwdfdb="http://www.xybec.com/ns/wwdfdb" version="1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.xybec.com/ns/wwdfdb Sample.xsd">
      wwdfdb:MyList
      <wwdfdb:Num id="3020">
      wwdfdb:Ver1.0.0.1</wwdfdb:Ver>
      wwdfdb:StatusInUse</wwdfdb:Status>
      </wwdfdb:Num>
      <wwdfdb:Num id="3021">
      wwdfdb:Ver1.0.0.1</wwdfdb:Ver>
      wwdfdb:StatusInUse</wwdfdb:Status>
      </wwdfdb:Num>
      </wwdfdb:MyList>
      </wwdfdb:DDB>

      Below is the xsd file for the xml file.

      <?xml version="1.0" encoding="UTF-8"?>
      <!--W3C Schema generated by XMLSpy v2009 sp1 (http://www.altova.com)-->
      <xs:schema xmlns="http://www.xybec.com/ns/wwdfdb" xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.xybec.com/ns/wwdfdb">
      <xs:element name="Ver">
      xs:simpleType
      <xs:restriction base="xs:string">
      <xs:enumeration value="1.0.0.1"/>
      </xs:restriction>
      </xs:simpleType>
      </xs:element>
      <xs:element name="Status">
      xs:simpleType
      <xs:restriction base="xs:string">
      <xs:enumeration value="InUse"/>
      </xs:restriction>
      </xs:simpleType>
      </xs:element>
      <xs:element name="Num">
      xs:complexType
      xs:sequence
      <xs:element ref="Ver"/>
      <xs:element ref="Status"/>
      </xs:sequence>
      <xs:attribute name="id" use="required">
      xs:simpleType
      <xs:restriction base="xs:short">
      <!--<xs:enumeration value="3020"/>
      <xs:enumeration value="3021"/>-->
      </xs:restriction>
      </xs:simpleType>
      </xs:attribute>
      </xs:complexType>
      </xs:element>
      <xs:element name="MyList">
      xs:complexType
      xs:sequence
      <xs:element ref="Num" maxOccurs="unbounded"/>
      </xs:sequence>
      </xs:complexType>
      <!--added below lines to achieve uniqueness for at

      S Offline
      S Offline
      Stuart Dootson
      wrote on last edited by
      #2

      In xmllint (libxml2's standalone app), I needed to add an explicit namespace specification for the elements in the unique spec:

      	<xs:unique name="MyUniqueID" xmlns:wwdfdb="http://www.xybec.com/ns/wwdfdb" >
      		<xs:selector xpath="wwdfdb:Num"/>
      		<xs:field xpath="@id"/>
      	</xs:unique>
      

      That did the right thing (validating uniqueness, rejecting sameness) in the limited testing I did!

      Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

      C 1 Reply Last reply
      0
      • S Stuart Dootson

        In xmllint (libxml2's standalone app), I needed to add an explicit namespace specification for the elements in the unique spec:

        	<xs:unique name="MyUniqueID" xmlns:wwdfdb="http://www.xybec.com/ns/wwdfdb" >
        		<xs:selector xpath="wwdfdb:Num"/>
        		<xs:field xpath="@id"/>
        	</xs:unique>
        

        That did the right thing (validating uniqueness, rejecting sameness) in the limited testing I did!

        Java, Basic, who cares - it's all a bunch of tree-hugging hippy cr*p

        C Offline
        C Offline
        Comp_Users
        wrote on last edited by
        #3

        It works.:thumbsup: Thanks a lot Stuart for the solution.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups