Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / XML / February 2007

Tip: Looking for answers? Try searching our database.

xml schema: elements with unique attribute values.

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Asko Telinen - 24 Feb 2007 12:57 GMT
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/


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.