Groups | Blog | Home
all groups > dotnet xml > february 2007 >

dotnet xml : xml schema: elements with unique attribute values.


Asko Telinen
2/24/2007 12:00:00 AM

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.

--
"It is not necessary to understand things in order to argue about them."
Martin Honnen
2/24/2007 2:23:37 PM
[quoted text, click to view]


[quoted text, click to view]

Put the unique requirement here e.g.
<xs:unique name="subsection-name">
<xs:selector xpath="subsection"/>
<xs:field xpath="@name"/>
</xs:unique>

[quoted text, click to view]

See also <http://www.w3.org/TR/xmlschema-0/#specifyingUniqueness>.

--

Martin Honnen --- MVP XML
AddThis Social Bookmark Button