Schema element contain text or elements, but not both.

Discussion in 'XML' started by Alan Johnson, Jul 24, 2007.

  1. Alan Johnson

    Alan Johnson Guest

    I am trying to specify that an element may contain simple content (an
    integer), or complex content (a sequence of two other elements), but not
    both. The listMember element in the following XML fragment demonstrates
    what I'm trying to accomplish:

    <list>
    <listMember>
    <ident>1</ident>
    <name>Name1</name>
    </listMember>
    <listMember>
    <ident>2</ident>
    <name>Name2</name>
    </listMember>
    </list>

    <list>
    <listMember>1</listMember>
    <listMember>2</listMember>
    </list>

    I cannot, however, figure out any way to create such a restriction. The
    following (invalid) schema sort of shows what it is I would like, but of
    course it is invalid because listMember is redeclared.

    <?xml version="1.0"?>

    <xs:schema
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns="exampleSchema"
    targetNamespace="exampleSchema"
    elementFormDefault="qualified">

    <xs:element name="list" type="List"/>

    <xs:complexType name="List">
    <xs:sequence minOccurs="0" maxOccurs="unbounded">
    <xs:choice>
    <xs:element name="listMember" type="ListMember"/>
    <xs:element name="listMember" type="xs:integer"/>
    </xs:choice>
    </xs:sequence>
    </xs:complexType>

    <xs:complexType name="ListMember">
    <xs:sequence>
    <xs:element name="indent" type="xs:integer"/>
    <xs:element name="name" type="xs:string"/>
    </xs:sequence>
    </xs:complexType>

    </xs:schema>

    Do any of you know how I could accomplish this?

    --
    Alan Johnson
    Alan Johnson, Jul 24, 2007
    #1
    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. Don Adams
    Replies:
    1
    Views:
    580
    Martin Honnen
    Mar 5, 2004
  2. Eric
    Replies:
    4
    Views:
    1,056
    Stan Kitsis [MSFT]
    Mar 7, 2007
  3. HANM
    Replies:
    2
    Views:
    695
    Joseph Kesselman
    Jan 29, 2008
  4. Roger Pack
    Replies:
    3
    Views:
    146
    Roger Pack
    Sep 28, 2010
  5. Jason Carlton
    Replies:
    11
    Views:
    232
    Dr J R Stockton
    Dec 8, 2009
Loading...

Share This Page