conditional processing for XSD elements?

Discussion in 'XML' started by Piper707@hotmail.com, Dec 6, 2005.

  1. Guest

    Hi,

    I need to know if there is any way of achieving conditional processing
    for XSD elements.

    ---------------------------------------------------------------
    <criteria></criteria> = a complex element
    <join_condition></join_condition> = a simple element
    ---------------------------------------------------------------
    EX:

    <criteria>....</criteria>
    <join_condition>.....</join_condition>
    <criteria> .....</criteria>
    ---------------------------------------------------------------

    I need the 1st criteria block to be mandatory. But it makes sense to
    have a second criteria block, only if a join condition block has been
    provided.

    so it would be illegal to have only:
    ---------------------------------------------------------------
    <criteria>....</criteria>
    <join_condition>.....</join_condition>
    ---------------------------------------------------------------
    I'm trying to impose the restriction: "if join_condition occurs once, a
    criteria block must occur once under it."

    I was trying to use the "group" conditional, but it points out
    xs:sequence to be illegal, i'm not sure why? -

    <xs:group name="criteria_and_join" minOccurs="0">
    <xs:sequence>
    <xs:element name="join_condition">
    <xs:simpleType>
    <xs:restriction base="xs:string">
    <xs:enumeration value="AND"/>
    <xs:enumeration value="OR"/>
    </xs:restriction>
    </xs:simpleType>
    </xs:element>
    <xs:element ref="criteria"/> //defined elewhere as a
    complex type
    </xs:sequence>
    </xs:group>

    How can achieve the conditional restriction that a criteria block can
    only appear provided a join_condition block precedes it (except for the
    very first criteria block)?

    Thanks
    Rohit.
    , Dec 6, 2005
    #1
    1. Advertising

  2. <xs:sequence>
    <xs:element name="criteria"/>
    <xs:sequence minOccurs="0">
    <xs:element name="join_condition"/>
    <xs:element name="criteria"/>
    </xs:sequence>
    </xs:sequence>

    --
    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 need to know if there is any way of achieving conditional processing
    > for XSD elements.
    >
    > ---------------------------------------------------------------
    > <criteria></criteria> = a complex element
    > <join_condition></join_condition> = a simple element
    > ---------------------------------------------------------------
    > EX:
    >
    > <criteria>....</criteria>
    > <join_condition>.....</join_condition>
    > <criteria> .....</criteria>
    > ---------------------------------------------------------------
    >
    > I need the 1st criteria block to be mandatory. But it makes sense to
    > have a second criteria block, only if a join condition block has been
    > provided.
    >
    > so it would be illegal to have only:
    > ---------------------------------------------------------------
    > <criteria>....</criteria>
    > <join_condition>.....</join_condition>
    > ---------------------------------------------------------------
    > I'm trying to impose the restriction: "if join_condition occurs once, a
    > criteria block must occur once under it."
    >
    > I was trying to use the "group" conditional, but it points out
    > xs:sequence to be illegal, i'm not sure why? -
    >
    > <xs:group name="criteria_and_join" minOccurs="0">
    > <xs:sequence>
    > <xs:element name="join_condition">
    > <xs:simpleType>
    > <xs:restriction base="xs:string">
    > <xs:enumeration value="AND"/>
    > <xs:enumeration value="OR"/>
    > </xs:restriction>
    > </xs:simpleType>
    > </xs:element>
    > <xs:element ref="criteria"/> //defined elewhere as a
    > complex type
    > </xs:sequence>
    > </xs:group>
    >
    > How can achieve the conditional restriction that a criteria block can
    > only appear provided a join_condition block precedes it (except for the
    > very first criteria block)?
    >
    > Thanks
    > Rohit.
    >
    Stan Kitsis [MSFT], Dec 6, 2005
    #2
    1. Advertising

  3. The only bug in your example (which should do what you want) (assuming
    there is a definition of 'criteria' somewhere), is the presence of the
    'minOccurs' attribute, which is not allowed on xs:group (because it's
    meaningless -- the min/max on the _reference_ to the group is what
    matters).

    ht
    --
    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, Dec 7, 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,079
    Markus
    Nov 22, 2005
  2. Alec S.
    Replies:
    10
    Views:
    10,084
    Alec S.
    Apr 16, 2005
  3. Rick Razzano

    XSD document for XSD defintion

    Rick Razzano, Sep 26, 2003, in forum: XML
    Replies:
    1
    Views:
    467
    C. M. Sperberg-McQueen
    Sep 26, 2003
  4. Replies:
    2
    Views:
    437
    Thorsten Stumpf
    May 24, 2008
  5. kanpeter

    conditional enumeration in XSD

    kanpeter, Oct 26, 2010, in forum: XML
    Replies:
    1
    Views:
    1,791
    Joe Kesselman
    Oct 27, 2010
Loading...

Share This Page