Hi all.
I´m a bit newbie writing xml schemas.
Is it possible to define xml element that must have unique attribute
values in same level. For example if i have a xml - document:
<list>
<subsection name="first">
<!-- subsection contents -->
</subsection>
<subsection name="first"> <!-- ERRROR!!! -->
<!-- subsection contents -->
</subsection>
<subsection name="second">
<!-- subsection contents -->
</subsection>
</list>
Schema:
<xs:complexType name ="subSectionType">
<xs:sequence>
<!-- the contents of subsection -->
</xs:sequence>
<!-- THIS ATTRIBUTE VALUE MUST BE UNIQUE INSIDE LIST ELEMENT -->
<xs:attribute name ="name" type="subSectionNameType" use="required" />
</xs:complexType>
<xs:element name="list" minOccurs="1" maxOccurs="1">
<xs:complexType>
<xs:sequence>
<xs:element name="subsection" type="subSectionType"
minOccurs="0" maxOccurs="unbounded" />
</xs:complexType>
</xs:element>
Here, the subsection element must have unique name attribute inside
list. The schema defines, that subsection element can appear only under
list element.
Is it possible or do i have to take care of it in application code?
Asko.

Signature
"It is not necessary to understand things in order to argue about them."
-- Pierre Beaumarchais (1732 - 1799)
Martin Honnen - 24 Feb 2007 13:23 GMT
> Is it possible to define xml element that must have unique attribute
> values in same level. For example if i have a xml - document:
[quoted text clipped - 10 lines]
> </subsection>
> </list>
> <xs:element name="list" minOccurs="1" maxOccurs="1">
> <xs:complexType>
> <xs:sequence>
> <xs:element name="subsection" type="subSectionType"
> minOccurs="0" maxOccurs="unbounded" />
> </xs:complexType>
Put the unique requirement here e.g.
<xs:unique name="subsection-name">
<xs:selector xpath="subsection"/>
<xs:field xpath="@name"/>
</xs:unique>
> </xs:element>
See also <http://www.w3.org/TR/xmlschema-0/#specifyingUniqueness>.

Signature
Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/