How do I allow both elements or No elements

Discussion in 'XML' started by Billy, Sep 9, 2005.

  1. Billy

    Billy Guest

    I have a current xsd that allows the xml to have 0..1 chassisid element
    and 0..1 terminalid element. But now I want to restrict these elements
    in a way that either both chassisid and terminalid are supplied or
    neither are supplies never just one of the elements is ever supplied.
    I believe this can be done but the restriction I have is that I cannot
    change the structure of the xml file, i.e. by nesting a new section for
    chassisid/terminalid.

    e.g.

    xsd:
    ....
    <xs:element name="chassisid" type="xs:string" minOccurs="0"
    maxOccurs="1"/>
    <xs:element name="terminalid" type="xs:string" minOccurs="0"
    maxOccurs="1"/>
    ....

    xml:
    ....
    <chassisid>A123456789</chassisid>
    <terminalid>A2345678</terminalid>
    ....

    If you can help then many thanks.

    Regards

    Billy
     
    Billy, Sep 9, 2005
    #1
    1. Advertising

  2. How about:

    <xs:sequence minOccurs="0" maxOccurs="1">
    <xs:element name="chassisid" type="xs:string"/>
    <xs:element name="terminalid" type="xs:string"/>
    </xs:sequence>

    Hope that helps,
    Priscilla

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

    *** Sent via Developersdex http://www.developersdex.com ***
     
    Priscilla Walmsley, Sep 9, 2005
    #2
    1. Advertising

  3. Billy wrote:
    > I have a current xsd that allows the xml to have 0..1 chassisid element
    > and 0..1 terminalid element. But now I want to restrict these elements
    > in a way that either both chassisid and terminalid are supplied or
    > neither are supplies never just one of the elements is ever supplied.


    <xs:complexType>
    <xs:sequence minOccurs="0" maxOccurs="1">
    <xs:element ref="chassisid"/>
    <xs:element ref="terminalid"/>
    </xs:sequence>
    </xs:complexType>

    --
    Klaus Johannes Rusch

    http://www.atmedia.net/KlausRusch/
     
    Klaus Johannes Rusch, Sep 9, 2005
    #3
  4. Billy

    Billy boy Guest

    Thanks for your time,

    It looks pretty simple and unsure why I haven't tried that already. I
    will try it Monday when I get back to work.

    Once again, thanks

    Billy



    *** Sent via Developersdex http://www.developersdex.com ***
     
    Billy boy, Sep 11, 2005
    #4
  5. Billy

    Billy Guest

    It works a treat, many thanks Priscilla & Klaus.

    Billy
     
    Billy, Sep 12, 2005
    #5
    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. Jeff
    Replies:
    2
    Views:
    962
    clintonG
    Sep 19, 2006
  2. Eric
    Replies:
    4
    Views:
    1,106
    Stan Kitsis [MSFT]
    Mar 7, 2007
  3. ABCL
    Replies:
    0
    Views:
    564
  4. Ryan Taylor
    Replies:
    1
    Views:
    694
    Ryan Taylor
    Sep 9, 2004
  5. Replies:
    1
    Views:
    121
Loading...

Share This Page