Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XML Schema: Alternative to all, choice, or sequence?

Status
Not open for further replies.

thenewa2x

Programmer
Dec 10, 2002
349
US
Here is my XML:
Code:
<document>
  <title>Document Title</title>
  <content>
    <section>
      <heading>Some Heading</heading>
      <paragraph>Some paragraph.</paragraph>
      <list>
        <item>Some list item.</item>
      </list>
    </section>
    <section>
      <heading>First Heading</heading>
      <heading>Second Heading</heading>
      <paragraph>First paragraph.</paragraph>
      <paragraph>Second paragraph.</paragraph>
      <list>
        <item>First list.</item>
      </list>
      <list>
        <item>Second list.</item>
      </list>
    </section>
    <section>
      <heading>First Heading</heading>
      <paragraph>First paragraph.</paragraph>
      <list>
        <item>First list.</item>
      </list>
      <heading>Second Heading</heading>
      <paragraph>Second paragraph.</paragraph>
      <list>
        <item>Second list.</item>
      </list>
    </section>
  </content>
</document>

I am trying to create a schema that will restrict the elements allowed in the [tt]<section/>[/tt] parent to [tt]<heading/>[/tt], [tt]<paragraph/>[/tt], and [tt]<list/>[/tt] but not necessarily in this order.

- I looked at [tt]<xs:all/>[/tt] but it requires that all elements appear atleast once, but [tt]<section/>[/tt] could be empty since all children elements are optional.
- I looked at [tt]<xs:choice/>[/tt] but it expects each child element to be a present once or not at all, but the children in [tt]<section/>[/tt] are multiply occurring.
- I looked at [tt]<xs:sequence/>[/tt] but it requires that the children elements be in a specific order, but the children in [tt]<section/>[/tt] can be in any order.

The closest option is [tt]<xs:choice/>[/tt] were it not for the restriction of only allowing non-multiply occurring children elements. Are there attributes to modify the behavior of any of these? I attempted to use the [tt]minOccurs[/tt] and [tt]maxOccurs[/tt] attributes but they did not help.

 
I figured it out. This is my version:

Code:
<xs:complexType name="content">
    <xs:choice minOccurs="0" maxOccurs="unbounded">
      <xs:element name="heading" type="target:text"/>
      <xs:element name="paragraph" type="target:text"/>
      <xs:element name="list" type="target:listing"/>
    </xs:choice>
  </xs:complexType>

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top