Get exactly one choice element

Discussion in 'XML' started by Mario, Dec 1, 2004.

  1. Mario

    Mario Guest

    Hi;

    I try to limit the selection of elements to exactly one. I have to do
    it by using elements, attributes are no alternativ.
    If I use the configuration shown below, it is also possible to select
    no element. If I set minOccurs to 1 at both elements, I have to select
    both. How I can can define that just one and no more than one element
    are allowed?

    Thx for your help!


    If I have the following xsd:
    ----------------------------------------------
    <?xml version="1.0" encoding="UTF-8"?>
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:element name="test">
    <xs:complexType>
    <xs:choice>
    <xs:element name="element1" minOccurs="0"/>
    <xs:element name="element2" minOccurs="0"/>
    </xs:choice>
    </xs:complexType>
    </xs:element>
    </xs:schema>

    and the following xml should not be allowed:
    -----------------------------------------------
    <?xml version="1.0" encoding="UTF-8"?>
    <test xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:noNamespaceSchemaLocation="schematest.xsd">
    </test>
    Mario, Dec 1, 2004
    #1
    1. Advertising

  2. Hi,

    If you use minOccurs="1", you don't need to have both elements present.
    Because you're using the <choice> group, it's a choice of one (and only
    one) of those elements.


    Hope that helps,
    Priscilla
    ----------------------------------
    Priscilla Walmsley
    Author, Definitive XML Schema
    http://www.datypic.com
    ----------------------------------

    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
    Priscilla Walmsley, Dec 3, 2004
    #2
    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. Mickey Segal
    Replies:
    0
    Views:
    847
    Mickey Segal
    Feb 2, 2004
  2. cayblood
    Replies:
    4
    Views:
    2,533
    Ivan Vecerina
    Nov 3, 2005
  3. BLUE
    Replies:
    2
    Views:
    371
    Priya Lakshminarayanan
    Mar 29, 2007
  4. miles.jg
    Replies:
    16
    Views:
    847
    Alf P. Steinbach
    Nov 14, 2007
  5. HANM
    Replies:
    2
    Views:
    682
    Joseph Kesselman
    Jan 29, 2008
Loading...

Share This Page