Re: Substitution group and abstract element

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"
         xsi:noNamespaceSchemaLocation="C:\Temp\Untitled10.xsd">
 	<textContent></textContent>
</rootElt>

OR

<rootElt xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:noNamespaceSchemaLocation="C:\Temp\Untitled10.xsd">
 	<base64Content></base64Content>
</rootElt>

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.

e.g.

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

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

<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.

Cheers,
Rahul.


> 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