W3C home > Mailing lists > Public > xmlschema-dev@w3.org > February 2002

Re: Substitution group and abstract element

From: Rahul Srivastava <Rahul.Srivastava@Sun.COM>
Date: Tue, 12 Feb 2002 14:53:16 +0000 (Asia/Calcutta)
Message-Id: <200202120928.g1C9Sxt22882@blr-root.India.Sun.COM>
To: xmlschema-dev@w3.org
Cc: regis.piccand@imtf.ch
I think something is wrong here. Let's see what. :-)

The schema is correct. Problem is with the instance document. Here what you are 
trying to achieve is not possible with this schema. This schema says you can 
have the following:

<rootElt xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"


<rootElt xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

Note that, you cannot use the element 'contentType' here as it is abstract. What 
you want, can be achieved by setting the type of element 'contentType' as a 
complexType which is abstract. Then having concrete complexTypes derived from 
that abstract complexType. Now you can use xsi:type in the instance doc. to 
specify the type of element to use.


<complexType name = "BaseType" abstract="true">
		<element name = "a" type = "string"/>
		<element name = "b" type = "string"/>
		<element name = "c" type = "string"/>

<complexType name = "DerivedType">
		<extension base="NS:BaseType">
				<element name = "d" type = "string"/>

<element name="contentType" type="NS:BaseType"/>

Now in your instance doc. you can have something like:

<contentType xsi:type="DerivedType">xxx</contentType>

Hope this helps.


> Piccand Régis wrote...
> Hi all,
> I am using a substitution group where the "head" element is abstract.
> In the instance document, I use the xsi:type to specify the type to use.
> However, it looks like the validator doesn't accept the types in the
> substitution group.
> the schema :
> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
> elementFormDefault="qualified" attributeFormDefault="unqualified">
> 	<xs:element name="rootElt">
> 		<xs:complexType>
> 			<xs:sequence>
> 				<xs:element ref="contentType"/>
> 			</xs:sequence>
> 		</xs:complexType>
> 	</xs:element>
> 	<xs:element name="textContent" type="xs:string"
> substitutionGroup="contentType"/>
> 	<xs:element name="base64Content" type="xs:base64Binary"
> substitutionGroup="contentType"/>
> 	<xs:element name="contentType" abstract="true"/>
> </xs:schema>
> The instance document : 
> <rootElt xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xsi:noNamespaceSchemaLocation="C:\Temp\Untitled10.xsd">
> 	<contentType xsi:type="textContent"></contentType>
> </rootElt>
> Error (XML Spy 4.3) : This file is not valid : Schema error - element or
> complexType 'contentType' is declared as abstract='true' ; please use
> xsi:type to specify a derived type that is not abstract, or use a member of
> a substitutionGroup instead.
> Am I doing something wrong here ?
> Thanks in advance for your help.
> Régis
Received on Tuesday, 12 February 2002 04:29:04 UTC

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 23:14:59 UTC