Unique costraint in XML Schema

H

hyppos

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?
 
M

Martin Honnen

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.
 
H

hyppos

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.
 
P

Priscilla Walmsley

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
 
H

Henry S. Thompson

Martin Honnen said:
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: (e-mail address removed)
URL: http://www.ltg.ed.ac.uk/~ht/
[mail really from me _always_ has this .sig -- mail without it is forged spam]
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top