Option between simple OR complex types in an XML Schema?

Discussion in 'XML' started by Steve, Jun 14, 2007.

  1. Steve

    Steve Guest

    Let's say I have an element that can contain a simple child element, OR
    a child element of complex type (but not both). For example, an actual
    XML snippet might look like this...

    <ValueMapping>
    <LocalValue>abc123</LocalValue>
    <RemoteValue>123abc</RemoteValue>
    </ValueMapping>

    ....or the XML might look like this...

    <ValueMapping>
    <LocalValue>abc123</LocalValue>
    <MultiValueList>
    <RemoteValue>123</RemoteValue>
    <RemoteValue>abc</RemoteValue>
    </MultiValueList>
    </ValueMapping>


    Is there an XML Schema I could write that would support both of these
    possibilies... allowing the "RemoteValue" to be either a simple element
    or a complex type of multiple elements (but not both at the same time)?
    Thanks in advance!
    Steve, Jun 14, 2007
    #1
    1. Advertising

  2. Steve wrote:
    > Let's say I have an element that can contain a simple child element, OR
    > a child element of complex type (but not both). For example, an actual
    > XML snippet might look like this...
    >
    > <ValueMapping>
    > <LocalValue>abc123</LocalValue>
    > <RemoteValue>123abc</RemoteValue>
    > </ValueMapping>
    >
    > ...or the XML might look like this...
    >
    > <ValueMapping>
    > <LocalValue>abc123</LocalValue>
    > <MultiValueList>
    > <RemoteValue>123</RemoteValue>
    > <RemoteValue>abc</RemoteValue>
    > </MultiValueList>
    > </ValueMapping>
    >
    >
    > Is there an XML Schema I could write that would support both of these
    > possibilies... allowing the "RemoteValue" to be either a simple element
    > or a complex type of multiple elements (but not both at the same time)?


    You can use xs:choice likt this:

    <xs:element name="ValueMapping">
    <xs:complexType>
    <xs:sequence>
    <xs:element name="LocalValue" type="xs:string"/>
    <xs:choice>
    <xs:element name="RemoteValue" type="xs:string"/>
    <xs:element name="MultiValueList">
    <xs:complexType>
    <xs:sequence>
    <xs:element name="RemoteValue" type="xs:string"
    maxOccurs="unbounded"/>
    </xs:sequence>
    </xs:complexType>
    </xs:element>
    </xs:choice>
    </xs:sequence>
    </xs:complexType>


    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
    Martin Honnen, Jun 14, 2007
    #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. Markus
    Replies:
    1
    Views:
    1,495
    Markus
    Nov 23, 2005
  2. Stanimir Stamenkov
    Replies:
    3
    Views:
    1,166
    Stanimir Stamenkov
    Apr 25, 2005
  3. Stanimir Stamenkov
    Replies:
    2
    Views:
    733
    Stanimir Stamenkov
    Oct 25, 2005
  4. Soren Kuula
    Replies:
    2
    Views:
    543
    Henry S. Thompson
    Dec 1, 2005
  5. MikeL
    Replies:
    2
    Views:
    264
    Dino Chiesa [Microsoft]
    Feb 22, 2005
Loading...

Share This Page