W3C home > Mailing lists > Public > xmlschema-dev@w3.org > March 2001

Re: Deriving a simple type from a complex type

From: Simon Cox <Simon.Cox@dem.csiro.au>
Date: Tue, 20 Mar 2001 09:23:16 +0800
Message-ID: <3AB6B104.5A01A02@dem.csiro.au>
To: "Henry S. Thompson" <ht@cogsci.ed.ac.uk>
CC: xmlschema-dev@w3.org
"Henry S. Thompson" wrote:
> 
> Simon Cox <Simon.Cox@dem.csiro.au> writes:
> 
> > Is it possible to constrain the character content of a
> > mixed complex type to be one of the built-in simple types?
> >
> > e.g.  if I have declared an anyType
> >
> >   <xsd:complexType name="FooType" mixed="true"/>
> >
> > can I then derive a type with simple content type="xsd:double"
> > by restriction from this?  How?
> 
> <xs:complexType>
>  <xs:simpleContent>
>   <xs:restriction base="FooType">
>    <xs:simpleType>
>      <xs:restriction base="xs:double"/>
>    </xs:simpleType>
>   </xs:restriction>
>  </xs:simpleContent>
> </xs:complexType>
> 
> Martin Gudgin was right when he said you can't get a _simple_ type
> definition by restricting a complex type definition.  Jeff Rafter was
> on the right track in suggesting that what was wanted was a complex
> type definition with simple content.
> 
> Note that _only_ <xs:restriction> within <xs:simpleContent> is allowed
> to have both a base attribute and explicit content, as above.

I tried what you suggest - see schema fragment below, 
with XMLSpy error message inserted inline. 
Is this a bug in XMLSpy?  

  <xsd:complexType name="AbstractQuantityType" mixed="true"/>

  <xsd:complexType name="CompactQuantityBaseType">
    <xsd:annotation>
      <xsd:documentation>Restricts AQT to double content</xsd:documentation>
    </xsd:annotation>
    <xsd:simpleContent>
      <xsd:restriction base="qf:AbstractQuantityType">
<!-- XMLSpy complains at previous line: 
"Schema error - undefined schema component 'base' encountered - 
simpleContent cannot have a base that is a complexType with complexContent" -->
        <xsd:simpleType>
          <xsd:restriction base="xsd:double"/>
        </xsd:simpleType>
      </xsd:restriction>
    </xsd:simpleContent>
  </xsd:complexType>

  <xsd:complexType name="CompactQuantityType">
    <xsd:annotation>
      <xsd:documentation>Amount + units - compact form</xsd:documentation>
    </xsd:annotation>
    <xsd:simpleContent>
      <xsd:extension base="qf:CompactQuantityBaseType">
        <xsd:attribute ref="qf:uom" use="optional"/>
      </xsd:extension>
    </xsd:simpleContent>
  </xsd:complexType>

  <xsd:complexType name="ExplicitQuantityType">
    <xsd:annotation>
      <xsd:documentation>Amount + Units - explicit form  - though I think we gotta empty AQT
first to force amount and uom to be the only content</xsd:documentation>
    </xsd:annotation>
    <xsd:complexContent>
      <xsd:extension base="AbstractQuantityType">
        <xsd:sequence>
          <xsd:element name="amount" type="xsd:double"/>
          <xsd:choice minOccurs="0">
            <xsd:element name="uomRef" type="xsd:uriReference"/>
            <xsd:element name="uomDefinition" type="xsd:string"/>
          </xsd:choice>
        </xsd:sequence>		
      </xsd:extension>
    </xsd:complexContent>
  </xsd:complexType>

-- 
Simon.Cox@dem.csiro.au    CSIRO Exploration & Mining
T:08 9284 8443 F:08 9389 1906 C:0403 302 672 (Intl +61)
http://www.ned.dem.csiro.au/research/visualisation/
Received on Monday, 19 March 2001 20:23:24 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Tuesday, 11 January 2011 00:14:20 GMT