RE: Question about combination of xsi:type and import

Hi,

sorry Eddie, but that's not quite what I want.
And your example gives me validation error, too.

To make a fresh start I have recheckd my files.
You will find them at the end.

There are four files:

1) Schema: tree.xsd
Target Namespace: "urn:tree"
Imports: nothing
Definitions:
element "tree"
complex type "branchType"
complex type "leafType" 

2) Schema: extLeaf.xsd
Target Namespace: "urn:extLeaf"
Imports: "urn:tree" (tree.xsd)
Definitions:
complex type "extendedLeafType" as derivation from "leafType"

3) Instance document: tree.xml
Defines namespace: xmlns:tree="urn:tree"
Uses only elements out of the namespace "urn:tree"
Validation: ok

4) Instance document: treeWithExtendedLeaf.xml
Defines namespace: xmlns:tree="urn:tree"
Defines namespace: xmlns:ext="urn:extLeaf"
Uses "tree:tree" element.
Uses "tree:leaf" but defines it's type as "ext:extendedLeafType".
"use xsi:schemaLocation" to let the parser find the "extLeaf" schema.
Uses the "ext:info" element from the "extendedLeafType" definition.

Validation (with XML Spy): This file is not valid.
Schema error - unkwon complex type "ext:extendedLeafType"
xsi:type must specify a known complex type


My question: Is XML Spy right on this ?
Why is "ext:extendedLeafType" unknown ? I've declared the namespace
for it, so the parser can find the schema.
What are the allowed types that I can reference inside "xsi:type".


The short version of the question is:
Can I reference types with "xsi:type" that are not in the schema for the
namespace of the element the "xsi:type" attribute is applied to, and also
not
in a schema imported by this namespace.

I've tried to understand the spec about this, but I do not quite get it.
http://www.w3.org/TR/2001/REC-xmlschema-1-20010502/#xsi_type

tree.xsd:
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema targetNamespace="urn:tree" xmlns:tns="urn:tree"
xmlns:xsd="http://www.w3.org/2000/10/XMLSchema"
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:schema>


extLeaf.xsd:
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema targetNamespace="urn:extLeaf"
xmlns:xsd="http://www.w3.org/2000/10/XMLSchema" xmlns:tree="urn:tree"
xmlns:tns="urn:extLeaf" elementFormDefault="qualified">
	<xsd:import namespace="urn:tree" schemaLocation="tree.xsd"/>
	<xsd:complexType name="extendedLeafType">
		<xsd:complexContent>
			<xsd:extension base="tree:leafType">
				<xsd:sequence>
					<xsd:element name="info"
type="xsd:string"/>
				</xsd:sequence>
			</xsd:extension>
		</xsd:complexContent>
	</xsd:complexType>
</xsd:schema>


tree.xml:
<?xml version="1.0" encoding="UTF-8"?>
<tree:tree xmlns:tree="urn:tree" xmlns:ext="urn:extLeaf"
xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance"
xsi:schemaLocation="urn:tree tree.xsd">
	<tree:leaf>
		<tree:name>eins</tree:name>
	</tree:leaf>
</tree:tree>



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

Received on Thursday, 17 May 2001 10:26:03 UTC