schema: different occurence types

T

Th.-Fischer

hi,
i have this xml structure
<users>
<user id="root"/> <!-- mandatory! -->
<user id="a"/> <!-- optional -->
<user id="b"/> <!-- optional -->
<user id="c"/> <!-- optional -->
</users>

what i like to define in schema is, that users
MUST HAVE 1 user element with id="root" and
CAN HAVE any other user elements.

My (not working) attempt (userRootType is derived
from userType with restriction pattern="root" for id):

<xsd:element name="users">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="user" type="fcms:userRootType"/>
<xsd:element name="user" type="fcms:userType"
minOccurs="0" maxOccurs="unbounded"
/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>

Is it possible, or need I different named elements?
Any Ideas?
 
S

Stan Kitsis [MSFT]

You cannot do this with XML Schema. Your best bet is something like:

<users>
<rootUser /> <!-- mandatory! -->
<user id="a"/> <!-- optional -->
<user id="b"/> <!-- optional -->
<user id="c"/> <!-- optional -->
</users>

--
Stan Kitsis
Program Manager, XML Technologies
Microsoft Corporation

This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm
 
H

Henry S. Thompson

Sure -- add a 'fixed' attribute called 'root' with value 'root' to the
<users> element, then define a <key>, which establishes id as a key
for user under users, and define a <keyref>, which identifies
root/@root as a reference to the 'id' key.

See the Identity Constraint chapter of the W3C XML Schema Primer [1] for
help with this.

ht

[1] http://www.w3.org/TR/xmlschema-0/#specifyingKeysAndtheirRefs
--
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,770
Messages
2,569,586
Members
45,085
Latest member
cryptooseoagencies

Latest Threads

Top