Question about combination of xsi:type and import

Hi.

A remark at the beginning: I have tried all this with XML Spy, so the
namespace URLs are
not that of the current XSDL spec. But the question remains the same.

Starting point is a schema that defines a tree structure.
Let's call it: tree.xsd

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema targetNamespace="urn:tree"
xmlns:xsd="http://www.w3.org/2000/10/XMLSchema" xmlns:tns="urn:tree"
elementFormDefault="qualified" attributeFormDefault="unqualified">
	<xsd:element name="tree" type="tns:branchType"/>
	<xsd:complexType name="leafType">
		<xsd:sequence>
			<xsd:element name="name" type="xsd:string"/>
		</xsd:sequence>
	</xsd:complexType>
	<xsd:complexType name="branchType">
		<xsd:choice maxOccurs="unbounded">
			<xsd:element name="leaf" type="tns:leafType"/>
			<xsd:element name="branch" type="tns:branchType"/>
		</xsd:choice>
	</xsd:complexType>
	<xsd:complexType name="extendedLeafType">
		<xsd:complexContent>
			<xsd:extension base="tns:leafType">
				<xsd:sequence>
					<xsd:element name="info"
type="xsd:string"/>
				</xsd:sequence>
			</xsd:extension>
		</xsd:complexContent>
	</xsd:complexType>
</xsd:schema>

This defines a derived type "extendedLeafType" by extension.

I can use this derived type inside an instance document like the following:

<?xml version="1.0" encoding="UTF-8"?>
<tree:tree xmlns:tree="urn:tree"
xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance">
	<tree:leaf xsi:type="tree:extendedLeafType">
		<tree:name>eins</tree:name>
		<tree:info>Test</tree:info>
	</tree:leaf>
</tree:tree>

Up until here there is no problem.

Now I want to do the following, but I don't know if it is possible. And if
it is possible I don't know how
to do it:

The definition of the derived "extendedLeafType" should be in another
namespace and therefor in another schema.
Let's call the schema custom.xsd. The custom.xsd needs to import the
tree.xsd schema.
The tree.xsd should not know anything about the custom.xsd, because the
custom.xsd is defined later (by some third party).

But I want to write instance documents that use the derived type. So I tried
the following:

<?xml version="1.0" encoding="UTF-8"?>
<tree:tree xmlns:tree="urn:tree" xmlns:custom="urn:custom"
xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance">
	<tree:leaf xsi:type="custom:extendedLeafType">
		<tree:name>eins</tree:name>
		<custom:info>Test</tree:info>
	</tree:leaf>
</tree:tree>

This does not work!
I've tried to validate this with XML Spy and get the error: "Unknown type
custom:extendedLeafType" (or something similiar).

Maybe a comparison with OOP programming makes things clearer:

The tree.xsd is like a library that defines some classes. The custom.xsd is
like another library that extends some of the classes
defined in tree.xsd. In my application I want to use most of the classes out
of tree.xsd but polymorphic substitute occurences
of "leafType" objects by "extendedLeafType" objects.

With Java or C++ this is no problem. But can I do the same with XSDL ?


Oliver Geisser
System Architect
CEYONIQ AG

Received on Wednesday, 16 May 2001 07:37:05 UTC