xsd puzzler

Discussion in 'XML' started by Anon, Oct 21, 2003.

  1. Anon

    Anon Guest

    Hi,

    Having trouble creating a schema. I want the following chunks xml to be
    acceptable

    <a>
    <b .... />
    </a>

    ...or...

    <a>
    <c .... />
    </a>

    So element a can can have sub-elements b or c.

    Constraints are: (1) a must have one of b or c, (2) a may only have one
    of b or c.

    The current schema I've got is as follows:

    <xs:choice maxOccurs="1" minOccurs="1">
    <xs:element name="b" type="typeB" minOccurs="0"/>
    <xs:element name="c" type="typeC" minOccurs="0"/>
    </xs:choice>

    However, although this schema satisfies constraint (2), it allows me to
    create element <a> without any sub-elements. In other words, the
    minOccurs of the choice is being ignored.

    Can anyone suggest an alternate approach?

    If it makes any difference I'm using XML Spy to create all of this, and
    will deploy to the MS Xml parser (whatever version is latest).

    TIA,
    Pete



    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
    Anon, Oct 21, 2003
    #1
    1. Advertising

  2. In article <3f951b64$0$194$>,
    Anon <> wrote:

    % Having trouble creating a schema. I want the following chunks xml to be
    % acceptable
    %
    % <a>
    % <b .... />
    % </a>
    %
    % ..or...
    %
    % <a>
    % <c .... />
    % </a>

    [...]

    % The current schema I've got is as follows:
    %
    % <xs:choice maxOccurs="1" minOccurs="1">
    % <xs:element name="b" type="typeB" minOccurs="0"/>
    % <xs:element name="c" type="typeC" minOccurs="0"/>
    % </xs:choice>

    So, why do you have minOccurs set to 0? If you just use the
    default values of minOccurs and maxOccurs, this should do
    exactly what you want.


    --

    Patrick TJ McPhee
    East York Canada
    Patrick TJ McPhee, Oct 21, 2003
    #2
    1. Advertising

  3. Anon

    Bob Foster Guest

    Remove the two minOccurs="0" as previously suggested.

    minOccurs="1" maxOccurs="1" on the choice (which, by the way, is the
    default) does not mean, as you may think, that the choice is constrained to
    output exactly one element, it means the choice is not optional. But the
    absence of any child elements matches both alternatives, so it is accepted.

    Maybe the XML syntax is confusing. If you wrote (b?|c?) I don't think you'd
    be surprised if it allowed no elements. Anyway, you shouldn't be.

    Bob Foster

    "Anon" <> wrote in message
    news:3f951b64$0$194$...
    > Hi,
    >
    > Having trouble creating a schema. I want the following chunks xml to be
    > acceptable
    >
    > <a>
    > <b .... />
    > </a>
    >
    > ..or...
    >
    > <a>
    > <c .... />
    > </a>
    >
    > So element a can can have sub-elements b or c.
    >
    > Constraints are: (1) a must have one of b or c, (2) a may only have one
    > of b or c.
    >
    > The current schema I've got is as follows:
    >
    > <xs:choice maxOccurs="1" minOccurs="1">
    > <xs:element name="b" type="typeB" minOccurs="0"/>
    > <xs:element name="c" type="typeC" minOccurs="0"/>
    > </xs:choice>
    >
    > However, although this schema satisfies constraint (2), it allows me to
    > create element <a> without any sub-elements. In other words, the
    > minOccurs of the choice is being ignored.
    >
    > Can anyone suggest an alternate approach?
    >
    > If it makes any difference I'm using XML Spy to create all of this, and
    > will deploy to the MS Xml parser (whatever version is latest).
    >
    > TIA,
    > Pete
    >
    >
    >
    > *** Sent via Developersdex http://www.developersdex.com ***
    > Don't just participate in USENET...get rewarded for it!
    Bob Foster, Oct 22, 2003
    #3
  4. Anon

    Pete Guest

    My code now works, and my understanding of MinOccurs has been increased.

    Thanks for your advice.

    Pete


    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
    Pete, Oct 27, 2003
    #4
    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. Jim Corey

    dropdown puzzler

    Jim Corey, Jan 16, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    359
    Jon Booth
    Jan 16, 2004
  2. Richard

    odd image puzzler

    Richard, Jan 4, 2004, in forum: HTML
    Replies:
    10
    Views:
    752
    Sid Ismail
    Jan 4, 2004
  3. Tim Daneliuk

    Tkinter Puzzler

    Tim Daneliuk, Jan 7, 2005, in forum: Python
    Replies:
    4
    Views:
    315
    Tim Daneliuk
    Jan 7, 2005
  4. Paul Rubin

    tkinter puzzler

    Paul Rubin, May 12, 2005, in forum: Python
    Replies:
    5
    Views:
    407
    Russell E. Owen
    May 16, 2005
  5. Replies:
    5
    Views:
    303
    Carlos Martinez
    Mar 31, 2006
Loading...

Share This Page