Link to home
Start Free TrialLog in
Avatar of pman
pman

asked on

XSD - list of complex elements (same name, different types)

Hello,

in an given XML file, there I found such an declaration:

...
<page>
...
  <module class="mod_text">
    <text>...</text>
  </module>
  <module class="mod_list">
    <list>...</list>
  </module>
  <module class="mod_complex">
    <tag1>
      <tag2>...</tag2>
    </tag1>
  </module>
  <module class="mod_text">
    <text>...</text>
  </module>
...
</page>
<page>
...more modules...
</page>

The content of the modules can be disparate. Each module type can occur at several positions per page, also more than one time at a page.

I tried it with these XSD, but it doesn't work:

<xsd:element name="page" minOccurs="0" maxOccurs="unbounded">
      <xsd:complexType>
            <xsd:sequence minOccurs="0" maxOccurs="unbounded">
                  <xsd:choice>
                        <xsd:element name="module" type="mod_text" minOccurs="0"/>
                        <xsd:element name="module" type="mod_list" minOccurs="0"/>
                        <xsd:element name="module" type="mod_complex" minOccurs="0"/>
                  </xsd:choice>
            </xsd:sequence>
      </xsd:complexType>
</xsd:element>

And the module definitions:

<xsd:complexType name="mod_text">
      <xsd:sequence>
            <xsd:element name="text" type"xsd:string" />
      </xsd:sequence>
      <xsd:attribute name="class" fixed="mod_text" use="required"/>
</xsd:complexType>
and so on...

Any idea how to define the XSD for this XML content?
ASKER CERTIFIED SOLUTION
Avatar of Gertone (Geert Bormans)
Gertone (Geert Bormans)
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial