W3C home > Mailing lists > Public > xmlschema-dev@w3.org > November 2011

How to define a complexType so that derived types can have simple content or complex content?

From: Costello, Roger L. <costello@mitre.org>
Date: Wed, 2 Nov 2011 20:05:51 +0000
To: "xmlschema-dev@w3.org" <xmlschema-dev@w3.org>
Message-ID: <B5FEE00B53CF054AA8439027E8FE177501B402@IMCMBX04.MITRE.ORG>
Hi Folks,

I would like to associate this title element with a complexType named property:

<title>The Implementation of Functional Programming Languages</title>

Notice that this "property element" has simple content.

I would like to associate this author element with the same property complexType:

    <author>
        <Person>
            <name>Simon L. Peyton Jones</name>
        </Person>
    </author>

Observe that this property element has complex content.

Thus, there are property elements with simple content and property elements with complex content.

How do I define a property complexType such that it can be restricted to simpleContent and extended to complexContent?

The following works, but I am not happy with it because it uses mixed="true" which I do not want. The <author> element has mixed content. Is there a way to implement this without requiring some property elements to have mixed content?   /Roger

    <xs:complexType name="property" abstract="true" mixed="true" />

    <xs:element name="title" type="titleType" />
    
    <xs:complexType name="titleType">
        <xs:simpleContent>
            <xs:restriction base="property">
                <xs:simpleType>
                    <xs:restriction base="xs:string">
                        <xs:maxLength value="100" />
                    </xs:restriction>
                </xs:simpleType>
            </xs:restriction>
        </xs:simpleContent>
    </xs:complexType>

    <xs:element name="author" type="authorType" />
    
    <xs:complexType name="authorType" mixed="true">
        <xs:complexContent>
            <xs:extension base="property">
                <xs:sequence>
                    <xs:element ref="Person" />
                </xs:sequence>
            </xs:extension>
        </xs:complexContent>
    </xs:complexType>
Received on Wednesday, 2 November 2011 20:08:51 UTC

This archive was generated by hypermail 2.3.1 : Wednesday, 7 January 2015 14:56:19 UTC