Unique costraint in XML Schema

Discussion in 'XML' started by hyppos, Jul 7, 2004.

  1. hyppos

    hyppos Guest

    Hi,
    I've a XML Schema with this user Type

    <xsd:simpleType name="ResultArrayType">
    <xsd:restriction base="xsd:nonNegativeInteger">
    <xsd:maxExclusive value="1000"/>
    </xsd:restriction>
    </xsd:simpleType>

    How can I add an unique costraint to this type?
    hyppos, Jul 7, 2004
    #1
    1. Advertising

  2. hyppos wrote:


    > I've a XML Schema with this user Type
    >
    > <xsd:simpleType name="ResultArrayType">
    > <xsd:restriction base="xsd:nonNegativeInteger">
    > <xsd:maxExclusive value="1000"/>
    > </xsd:restriction>
    > </xsd:simpleType>
    >
    > How can I add an unique costraint to this type?


    You can use <xsd:unique> at the place where you use this type for an
    element definition I think.

    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
    Martin Honnen, Jul 7, 2004
    #2
    1. Advertising

  3. hyppos

    hyppos Guest


    > > I've a XML Schema with this user Type
    > >
    > > <xsd:simpleType name="ResultArrayType">
    > > <xsd:restriction base="xsd:nonNegativeInteger">
    > > <xsd:maxExclusive value="1000"/>
    > > </xsd:restriction>
    > > </xsd:simpleType>
    > >
    > > How can I add an unique costraint to this type?

    >
    > You can use <xsd:unique> at the place where you use this type for an
    > element definition I think.
    >
    > --


    Could you give me an example?
    hyppos, Jul 7, 2004
    #3
  4. hyppos

    hyppos Guest


    > You can use <xsd:unique> at the place where you use this type for an
    > element definition I think.
    >

    Like This?

    <xsd:simpleType name="ResultArrayType">
    <xsd:restriction base="xsd:unique">
    <xsd:maxExclusive value="1000"/>
    </xsd:restriction>
    </xsd:simpleType>

    unfortunately, doesn't work.
    hyppos, Jul 7, 2004
    #4
  5. Hi,

    You specify the uniqueness constraint on the element, not the type. For
    example, if you had an element named "Number" with that type, and you
    wanted its value to be unique within the scope of its parent element
    "listOfNumbers", it would look something like this:


    <xs:element name="listOfNumbers">
    <xs:complexType>
    <xs:sequence>
    <xs:element name="Number" type="ResultArrayType"
    maxOccurs="unbounded"/>
    </xs:sequence>
    </xs:complexType>
    <xs:unique name="uniqueNum">
    <xs:selector xpath="Number"/>
    <xs:field xpath="."/>
    </xs:unique>
    </xs:element>

    Hope that helps,
    Priscilla

    -----------------------------------------------------
    Priscilla Walmsley
    Author, Definitive XML Schema (Prentice Hall PTR)
    http://www.datypic.com
    -----------------------------------------------------

    *** Sent via Devdex http://www.devdex.com ***
    Don't just participate in USENET...get rewarded for it!
    Priscilla Walmsley, Jul 7, 2004
    #5
  6. hyppos wrote:

    >>You can use <xsd:unique> at the place where you use this type for an
    >>element definition I think.
    >>

    >
    > Like This?
    >
    > <xsd:simpleType name="ResultArrayType">
    > <xsd:restriction base="xsd:unique">
    > <xsd:maxExclusive value="1000"/>
    > </xsd:restriction>
    > </xsd:simpleType>
    >
    > unfortunately, doesn't work.


    No, a type can't be unique, only an element or attribute in a certain
    scope, see the example in
    http://www.w3.org/TR/xmlschema-0/#specifyingUniqueness

    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
    Martin Honnen, Jul 7, 2004
    #6
  7. Martin Honnen <> writes:

    > No, a type can't be unique, only an element or attribute in a certain
    > scope, see the example in
    > http://www.w3.org/TR/xmlschema-0/#specifyingUniqueness


    The advice is good, but there are a few glitches in the original
    version of the Primer -- a better reference is the draft 2nd edition
    at

    http://www.w3.org/TR/2004/PER-xmlschema-0-20040318/#specifyingUniqueness

    ht
    --
    Henry S. Thompson, HCRC Language Technology Group, University of Edinburgh
    Half-time member of W3C Team
    2 Buccleuch Place, Edinburgh EH8 9LW, SCOTLAND -- (44) 131 650-4440
    Fax: (44) 131 650-4587, e-mail:
    URL: http://www.ltg.ed.ac.uk/~ht/
    [mail really from me _always_ has this .sig -- mail without it is forged spam]
    Henry S. Thompson, Jul 8, 2004
    #7
  8. hyppos

    hyppos Guest

    Thks to Everybody
    hyppos, Jul 9, 2004
    #8
    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. Markus
    Replies:
    1
    Views:
    1,519
    Markus
    Nov 23, 2005
  2. Fred Smith
    Replies:
    1
    Views:
    938
    Martin Honnen
    Feb 5, 2004
  3. Hari Om
    Replies:
    1
    Views:
    461
    Martin SChukrazy
    Mar 2, 2004
  4. Stanimir Stamenkov
    Replies:
    3
    Views:
    1,244
    Stanimir Stamenkov
    Apr 25, 2005
  5. Replies:
    3
    Views:
    2,829
Loading...

Share This Page