DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 1 of 1
  1. #1
    Join Date
    Aug 2006

    xsd:key validates with identical keys

    Dear devx, thanks for hosting an XML forum

    For my first post, I would like to share a small problem I have had with unique keys. I wrote a simple schema for a note taking scenario which I called Notebook.xsd. Here is the code:

    <xsd:group name="NoteGroup">
    <xsd:element name="content" type="xsd:string" minOccurs="1" maxOccurs="1"/>
    <xsd:element name="reference" type="xsd:string" minOccurs="1" maxOccurs="1"/>

    <xsd:complexType name="NoteType">
    <xsd:group ref="NoteGroup"/>
    <xsd:attribute name="id" type="xsd:integer"/>

    <xsd:element name="NoteBook">
    <xsd:element name="Note" type="NoteType" minOccurs="1" maxOccurs="unbounded">
    <xsd:key name="key">
    <xsd:selector xpath="."/>
    <xsd:field xpath="@id"/>


    In red, is the code for a unique key for every <Note> element. The following is a test xml file I wrote to accompany the schema:

    <Note id="1">
    <Note id="1">
    <Note id="3">

    I have removed the extra tags like <schema> in the first case and the xml declarations for berevity.

    I would hope that the validation of the test file should fail with duplicate keys (1) in red, but it passes validation across many different parsers. I therefore think something is wrong with my code. Can anybody spot it?

    Last edited by domlogic; 08-21-2006 at 11:45 AM. Reason: More clarity in XML code (dropped namespace prefix)

Similar Threads

  1. get the array of keycodes for the keys that were pressed
    By Michael \(michka\) Kaplan in forum VB Classic
    Replies: 8
    Last Post: 06-07-2002, 09:23 PM
  2. Replication problem with foreign keys
    By Rimvis in forum Database
    Replies: 3
    Last Post: 03-19-2002, 07:45 AM
  3. Replies: 0
    Last Post: 07-18-2001, 05:11 PM
  4. Replies: 0
    Last Post: 07-18-2001, 05:11 PM
  5. Primary keys & Triggers???
    By Beginner-Brad in forum Database
    Replies: 1
    Last Post: 01-24-2001, 10:11 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
Latest Articles
Questions? Contact us.
Web Development
Latest Tips
Open Source

   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.