schema: different occurence types

Discussion in 'XML' started by Th.-Fischer@web.de, Aug 31, 2005.

  1. Guest

    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?
    , Aug 31, 2005
    #1
    1. Advertising

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


    <> wrote in message
    news:...
    > 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?
    >
    Stan Kitsis [MSFT], Aug 31, 2005
    #2
    1. Advertising

  3. 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:
    URL: http://www.ltg.ed.ac.uk/~ht/
    [mail really from me _always_ has this .sig -- mail without it is forged spam]
    Henry S. Thompson, Sep 1, 2005
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Markus
    Replies:
    1
    Views:
    1,497
    Markus
    Nov 23, 2005
  2. Stanimir Stamenkov
    Replies:
    3
    Views:
    1,170
    Stanimir Stamenkov
    Apr 25, 2005
  3. Soren Kuula
    Replies:
    1
    Views:
    439
    Henry S. Thompson
    Dec 1, 2005
  4. utab
    Replies:
    3
    Views:
    310
    Pavel
    May 8, 2006
  5. MikeL
    Replies:
    2
    Views:
    264
    Dino Chiesa [Microsoft]
    Feb 22, 2005
Loading...

Share This Page