tags:

views:

11

answers:

1

I am trying to create an XML Schema that will allow both text and elements in the element <content> with an unlimited number of <a>, <b> and <c> element in any order. An example XML would be below.

<xml version="1.0" encoding="UTF-8"?>
<article xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="article.xsd">
    <content>Lorem <a>ipsum</a> dolor sit amet, consectetur adipiscing elit. Nulla rhoncus <b>laoreet neque</b> ac mollis. <a>Aliquam</a> erat <c>volutpat</c>. Nunc ante turpis, placerat eu mattis eu, egestas eu elit.
    </content>
</article>

I'm finding it difficult to allow any number of those elements in any order.

A: 

You need to use a mixed content type. There's a simple to understand description of them here.

Something like this:

<xs:element name="article">
  <xs:complexType mixed="true">
    <xs:choice minOccurs="0" maxOccurs="unbounded">
      <xs:element name="a" type="xs:string"/>
      <xs:element name="b" type="xs:string"/>
      <xs:element name="c" type="xs:string"/>
    </xs:choice >
  </xs:complexType>
</xs:element>

The part to note is mixed="true", which allows text to appear between the elements.

skaffman