Unique constraints not working - please help

Discussion in 'XML' started by pr@paulrichards.me.uk, Mar 13, 2008.

  1. Guest

    I have the following sample XML File:

    <?xml version="1.0" encoding="UTF-8" standalone="no"?>
    <parent>
    <child ref="1"><grandchild>tom</grandchild></child>
    <child ref="1"><grandchild>harry</grandchild></child>
    </parent>

    And the schema is:

    <?xml version="1.0" encoding="ISO-8859-1" ?>
    <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" >
    <xsd:simpleType name = "oneormore">
    <xsd:restriction base="xsd:integer">
    <xsd:minInclusive value="1"/>
    </xsd:restriction>
    </xsd:simpleType>
    <xsd:element name="parent">
    <xsd:complexType>
    <xsd:sequence minOccurs="1" maxOccurs="unbounded">
    <!-- A chart consists of several rows -->
    <xsd:element name="child">
    <xsd:complexType>
    <xsd:sequence minOccurs="1" maxOccurs="unbounded">
    <xsd:element name="grandchild" type = "xsd:string"/>
    </xsd:sequence>
    <xsd:attribute name="ref" type="xsd:integer" use="required"/>
    </xsd:complexType>
    </xsd:element>
    </xsd:sequence>
    </xsd:complexType>
    <!-- This is not working -->
    <xsd:unique name="rowID">
    <xsd:selector xpath="parent/child"/>
    <xsd:field xpath="@ref"/>
    </xsd:unique>
    </xsd:element>
    </xsd:schema>

    The problem is that my XML file validates successfully in my Java
    (DOM) app, despite the fact that the values of the ref attributes in
    the child element are NOT unique (we have two occurrences of "1").

    Is this a bug in the parser, or have I done something wrong in my
    schema?
    , Mar 13, 2008
    #1
    1. Advertising

  2. Pavel Lepin Guest

    <> wrote in
    <>:
    > <?xml version="1.0" encoding="UTF-8" standalone="no"?>
    > <parent>
    > <child ref="1"><grandchild>tom</grandchild></child>
    > <child ref="1"><grandchild>harry</grandchild></child>
    > </parent>
    >
    > And the schema is:
    >
    > <?xml version="1.0" encoding="ISO-8859-1" ?>
    > <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" >
    > <xsd:element name="parent">
    > <xsd:complexType>


    [...]

    > </xsd:complexType>
    > <!-- This is not working -->
    > <xsd:unique name="rowID">
    > <xsd:selector xpath="parent/child"/>
    > <xsd:field xpath="@ref"/>
    > </xsd:unique>
    > </xsd:element>
    > </xsd:schema>
    >
    > Is this a bug in the parser, or have I done something
    > wrong in my schema?


    Try and guess. parent element in your document doesn't have
    any parent element children.

    <xsd:unique name="rowID">
    <xsd:selector xpath="child"/>
    <xsd:field xpath="@ref"/>
    </xsd:unique>

    --
    "...a Netscape engineer who shan't be named once passed a
    pointer to JavaScript, stored it as a string and later
    passed it back to C, killing 30..." --Blake Ross
    Pavel Lepin, Mar 14, 2008
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. bazzer
    Replies:
    1
    Views:
    4,963
    =?Utf-8?B?Y2xpY2tvbg==?=
    Apr 6, 2006
  2. ToshiBoy
    Replies:
    6
    Views:
    846
    ToshiBoy
    Aug 12, 2008
  3. Arved Sandstrom
    Replies:
    1
    Views:
    1,181
    Arved Sandstrom
    Aug 17, 2008
  4. Bobby Edward
    Replies:
    4
    Views:
    7,680
    sloan
    Nov 3, 2008
  5. Kjetil Skotheim
    Replies:
    0
    Views:
    105
    Kjetil Skotheim
    Jun 16, 2004
Loading...

Share This Page