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

Posted on 2009-12-16
Last Modified: 2013-11-18

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

  <module class="mod_text">
  <module class="mod_list">
  <module class="mod_complex">
  <module class="mod_text">
...more modules...

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:sequence minOccurs="0" maxOccurs="unbounded">
                        <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"/>

And the module definitions:

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

Any idea how to define the XSD for this XML content?
Question by:pman
    1 Comment
    LVL 60

    Accepted Solution

    you can't!!!

    XSD does not allow you to have elements with different types but the same name in the same scope
    (at least not schema1.0, that will change with assertions in schema 1.1)

    The only thing you can do is make the model for the module element very broad
    and use schematron to build the restirctions based on the value of the class attribute

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Training Course: Adobe Dreamweaver CC 2015

    Adobe Dreamweaver Creative Cloud is used by web designers and front-end developers and allows you to visualize your site in real-time as you code. This course covers exam objectives for the Adobe Certified Associate (ACA) certification.

    Preface In the first article: A Better Website Login System ( I introduced the EE Collaborative Login System and its intended purpose. In this article I will discuss some of the design consideratio…
    Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL ( several years ago, it seemed like now was a good time to updat…
    Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
    The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now