troubleshooting Question

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

Avatar of pman
pman asked on
Web Languages and StandardsXML
1 Comment1 Solution1345 ViewsLast Modified:
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?
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 1 Comment.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 1 Comment.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros