Making atleast one of multiple optional elements mandatory

Discussion in 'XML' started by ANoobee, Mar 2, 2007.

  1. ANoobee

    ANoobee Guest

    What is the best approach to force atleast one of a few optional
    elements required in an XSD?
    This is what I'm tring to do:

    <email>
    <to>
    <cc>
    <bcc>
    </email>

    where to, cc and bcc are optional but email should contain atleast one
    of them.

    Thanks for any inputs.
    ANoobee, Mar 2, 2007
    #1
    1. Advertising

  2. ANoobee

    ANoobee Guest

    On Mar 2, 12:46 pm, "ANoobee" <> wrote:
    > What is the best approach to force atleast one of a few optional
    > elements required in an XSD?
    > This is what I'm tring to do:
    >
    > <email>
    > <to>
    > <cc>
    > <bcc>
    > </email>
    >
    > where to, cc and bcc are optional but email should contain atleast one
    > of them.
    >
    > Thanks for any inputs.


    Additional information...
    The order in which the to, cc and bcc occur does not matter and each
    of them will be un-bounded.
    ANoobee, Mar 2, 2007
    #2
    1. Advertising

  3. "ANoobee" <> writes:

    > > What is the best approach to force atleast one of a few optional
    > > elements required in an XSD?
    > > This is what I'm tring to do:
    > >
    > > <email>
    > > <to>
    > > <cc>
    > > <bcc>
    > > </email>
    > >
    > > where to, cc and bcc are optional but email should contain atleast one
    > > of them.
    > >

    >
    > Additional information...
    > The order in which the to, cc and bcc occur does not matter and each
    > of them will be un-bounded.



    You can use sequence of choice's for that:

    <complexType name="email">
    <sequence maxOccurs="unbounded">
    <choice>
    <element name="to" type="string"/>
    <element name="cc" type="string"/>
    <element name="bcc" type="string"/>
    </choice>
    </sequence>
    </complexType>


    hth,
    -boris

    --
    Boris Kolpackov
    Code Synthesis Tools CC
    http://www.codesynthesis.com
    Open-Source, Cross-Platform C++ XML Data Binding
    Boris Kolpackov, Mar 2, 2007
    #3
  4. ANoobee

    Guest

    On 2 Mar, 19:49, Boris Kolpackov wrote:
    > "ANoobee" writes:
    > > > What is the best approach to force atleast one of a few optional
    > > > elements required in an XSD?
    > > > This is what I'm tring to do:

    >
    > > > <email>
    > > > <to>
    > > > <cc>
    > > > <bcc>
    > > > </email>

    >
    > > > where to, cc and bcc are optional but email should contain atleast one
    > > > of them.

    >
    > > Additional information...
    > > The order in which the to, cc and bcc occur does not matter and each
    > > of them will be un-bounded.

    >
    > You can use sequence of choice's for that:
    >
    > <complexType name="email">
    > <sequence maxOccurs="unbounded">
    > <choice>
    > <element name="to" type="string"/>
    > <element name="cc" type="string"/>
    > <element name="bcc" type="string"/>
    > </choice>
    > </sequence>
    > </complexType>


    Or even:

    <complexType name="email">
    <choice maxOccurs="unbounded">
    <element name="to" type="string"/>
    <element name="cc" type="string"/>
    <element name="bcc" type="string"/>
    </choice>
    </complexType>

    Pete.
    --
    =============================================
    Pete Cordell
    Tech-Know-Ware Ltd
    for XML to C++ data binding visit
    http://www.tech-know-ware.com/lmx/
    http://www.codalogic.com/lmx/
    =============================================
    , Mar 2, 2007
    #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. Piers Chivers
    Replies:
    2
    Views:
    382
    Piers Chivers
    Mar 2, 2004
  2. Abhinav
    Replies:
    1
    Views:
    680
    Abhinav
    Jul 22, 2004
  3. Thomas Wittek
    Replies:
    4
    Views:
    1,462
    Joe Kesselman
    Sep 13, 2007
  4. byrnejb
    Replies:
    0
    Views:
    97
    byrnejb
    Jul 15, 2010
  5. MT

    making a text field mandatory?

    MT, Oct 9, 2003, in forum: Javascript
    Replies:
    4
    Views:
    168
Loading...

Share This Page