- From: <Simon.Cox@csiro.au>
- Date: Wed, 9 Jan 2002 15:03:46 +0800
- To: xmlschema-dev@w3.org
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. 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? 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.) This might also be related to an exchange from last year: > -----Original Message----- > From: Priscilla Walmsley [mailto:priscilla@walmsley.com] > Sent: Saturday, 20 October 2001 1:02 AM > To: 'Jeni Tennison'; 'Priscilla Walmsley' > Cc: xmlschema-dev@w3.org > Subject: RE: constraining an element to be either simple or complex > content > > > Hi Jeni, > > That's a good point, and I think we may have uncovered a > contradiction in > the Rec. The section I was looking at is Derivation Valid > (Restriction, > Complex) in clause 5: > > 5.1 If the {content type} of the complex type definition is a > simple type > definition, then one of the following must be true: > 5.1.1 The {content type} of the {base type definition} must > be a simple type > definition of which the {content type} is a ·valid > restriction· as defined > in Derivation Valid (Restriction, Simple) (§3.14.6). > 5.1.2 The {base type definition} must be mixed and have a > particle which is > ·emptiable· as defined in Particle Emptiable (§3.9.6). > > Unless maybe I should have used "complexContent"? I will investigate > further.... > > Priscilla > ----------------------------------------------------------- > Priscilla Walmsley priscilla@walmsley.com > Vitria Technology http://www.vitria.com > Author, Definitive XML Schema (Prentice Hall, Dec. 2001) > ----------------------------------------------------------- > > > -----Original Message----- > > From: Jeni Tennison [mailto:jeni@jenitennison.com] > > Sent: Friday, October 19, 2001 12:44 PM > > To: Priscilla Walmsley > > Cc: xmlschema-dev@w3.org > > Subject: Re: constraining an element to be either simple or complex > > content > > > > > > Hi Priscilla, > > > > > You can't extend simple content to create complex content, but you > > > _can_ restrict mixed complex content to create simple content. In > > > this situation, you would define the types as: > > > > > > <xs:complexType name="baseType" mixed="true" abstract="true"> > > > <xs:sequence> > > > <xs:any minOccurs="0" maxOccurs="unbounded"/> > > > </xs:sequence> > > > </xs:complexType> > > > > > > <xs:complexType name="simpleType"> > > > <xs:simpleContent> > > > <xs:restriction base="baseType"> > > > <xs:simpleType> > > > <xs:restriction base="xs:integer"/> > > > </xs:simpleType> > > > </xs:restriction> > > > </xs:simpleContent> > > > </xs:complexType> > > > > Wow, that is obscure! It works in XSV, but I'm confused about why, > > because Clause 2 of the Complex Type Definition Representation OK > > Schema Representation Constraint says: > > > > 2 If the <simpleContent> alternative is chosen, the type > > definition ·resolved· to by the ·actual value· of the base > > [attribute] must be either a complex type definition whose > > {content type} is a simple type definition or, only if the > > <extension> alternative is also chosen, a simple type > definition; > > > > but the base attribute in the definition of the > 'simpleType' type is a > > complex type definition whose {content type} is a *complex* type > > definition, isn't it? > > > > Or am I reading it wrong? > > > > Cheers, > > > > Jeni > > > > --- > > Jeni Tennison > > http://www.jenitennison.com/ > > > > >
Received on Wednesday, 9 January 2002 02:11:11 UTC