Re: Deriving a simpleContent element from an anyType or anySimpleType

Simon.Cox@csiro.au writes:

> This one comes up in various guises from time to time.  
> I think I know the answer but I want to check.  
> 
> It is desirable to be able to define a type by restriction 
> of an abstract type so that the content model is various specific
> simpleTypes.  
> One model pattern that was proposed goes like this.  Start with:
> 
> <xs:complexType name="baseType" abstract="true">
>   <xs:attribute name="a1" type="string">
> </xs:complexType>
> 
> which is an (empty) "anyType" by implication.  

Stop right there.  It's not any kind of "anyType", it's an empty
complex type.  So you can't restrict its content in any useful way --
empty is as restricted as it gets.

To get what you want (content model as per "anyType", one attribute),
you need

<xs:complexType name="baseType" abstract="true">
  <xs:sequence>
   <xs:any processContents="lax" minOccurs="0" maxOccurs="unbounded"/>
  </xs:sequence>
  <xs:attribute name="a1" type="string">
</xs:complexType>


> Then "restrict" the content to be simpleContent.  e.g.:
> 
> <xs:complexType name="integerType">
>    <xs:simpleContent>
>      <xs:restriction base="baseType">
>        <xs:simpleType>
>          <xs:restriction base="xs:integer"/>
>        </xs:simpleType>
>      </xs:restriction>
>    </xs:simpleContent>
> </xs:complexType>
> 
> to get an integer with an attribute, and   
> 
> <xs:complexType name="stringType">
>    <xs:simpleContent>
>      <xs:restriction base="baseType">
>        <xs:simpleType>
>          <xs:restriction base="xs:string"/>
>        </xs:simpleType>
>      </xs:restriction>
>    </xs:simpleContent>
> </xs:complexType>
> 
> to get a string with the same attribute.  
> 
> Problem is, this appears to violate the third sub-clause of  
> http://www.w3.org/TR/xmlschema-2/#defn-rep-constr 
> 
> Am I reading this right?  

There's a known issue here, the REC is contradictory, so some
validators allow what I've shown above, and some don't.  There will be
an erratum soon to fix the contradiction.

> So: is there a way to accomplish what I'm trying do here? 
> (i.e. have various simpleContent types inherit the same 
> attribute, and sit within a single type-derivation hierarchy, 
> and thus be able to support elements that fit in a substitutionGroup.)  

Yes, use this instead:

<xs:complexType name="baseType" abstract="true">
  <xs:simpleContent>
   <xs:extension base="xs:anySimpleType">
    <xs:attribute name="a1" type="string">
   </xs:extension>
  </xs:simpleContent>
</xs:complexType>


> This might also be related to an exchange from last year:  

<snip
 href="http://lists.w3.org/Archives/Public/xmlschema-dev/2001Oct/0172.html"/>

Yes, it is.

ht
-- 
  Henry S. Thompson, HCRC Language Technology Group, University of Edinburgh
          W3C Fellow 1999--2001, part-time member of W3C Team
     2 Buccleuch Place, Edinburgh EH8 9LW, SCOTLAND -- (44) 131 650-4440
	    Fax: (44) 131 650-4587, e-mail: ht@cogsci.ed.ac.uk
		     URL: http://www.ltg.ed.ac.uk/~ht/

Received on Wednesday, 9 January 2002 04:24:11 UTC