Question: validity of type overide with union type

I am unable to determine the intent and meaning of section
3.14.6 Constraints on Simple Type Definition Schema Components

My recall is that the intent of instance type overides is
ONLY to apply stricter constraints on the data to be validated.
yet, when working an example, the use in extensibility deriving
alternative types became apparent.


Read one way,
	1) unitedColor is validly derived by union from rgbColor and the
		instance is valid.

	If So, the text in parenthesis is not normative and confusing.


     or another way

	2) unitedColor is NOT validly derived from rgbColor because
		it is not derived by restriction and therefore
		the instance is not valid.

	If so, why is union in the list?


------ Analysis----

My guess: the first two test-colors are valid, the last three are not.
xsi:type can be a built-in type or a globally defined type in
the schema but must be a type that is derived from the original
type of the element or attribute.

I think the ruling clause is:
    2.2.4 does not apply because B (rgbColor) is not an union.

    2.2.2 D's ·base type definition· is not the ·simple ur-type definition·
	and is validly derived from B given the subset, as defined by
	this constraint.

where in this case, B (rgbColor) is restriction of unsignedByte

when D = unitedColor - The fact that a union exists should have no
impact, the union is in D's variety and the text in the first para says
"of which only restriction is actually relevant"

Yet, the only reason to believe that it is not validly derived
is the clause 2.2.2. This logic becomes circular.



Regards,
Dave Hollander

--------------------------- EXAMPLE ----------------

xsd Sample:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
elementFormDefault="qualified" attributeFormDefault="unqualified">
	<xs:element name="TEST-OverrideError">
		<xs:annotation>
			<xs:documentation>This test the detaction of ilegal
				instance overrides.</xs:documentation>
		</xs:annotation>
		<xs:complexType>
			<xs:sequence>
				<xs:element name="test-color" type="rgbColor" maxOccurs="unbounded">
				</xs:element>
			</xs:sequence>
		</xs:complexType>
	</xs:element>

	<xs:simpleType name="colorName">
		<xs:restriction base="xs:string">
			<xs:enumeration value="red"/>
			<xs:enumeration value="green"/>
			<xs:enumeration value="blue"/>
		</xs:restriction>
	</xs:simpleType>
	<xs:simpleType name="rgbColor">
		<xs:restriction>
			<xs:simpleType>
				<xs:list itemType="xs:unsignedByte"/>
			</xs:simpleType>
			<xs:length value="3"/>
		</xs:restriction>
	</xs:simpleType>
	<xs:simpleType name="unitedColor">
		<xs:union memberTypes="colorName rgbColor"/>
	</xs:simpleType>
	</xs:schema>

<!-- and the instance -->

<?xml version="1.0" encoding="UTF-8"?>
<TEST-OverrideError
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns:xs="http://www.w3.org/2001/XMLSchema"
	xsi:noNamespaceSchemaLocation=".\OverrideTest.xsd">

	<test-color>0 250 48</test-color>
	<test-color xsi:type="colorName">red</test-color>
	<test-color xsi:type="unitedColor">green</test-color>
	<test-color xsi:type="someType">34590</test-color>
	<test-color xsi:type="xs:gYear">1993</test-color>
</TEST-OverrideError>


----------------------------------------------------------------------------
---
Relevent portions of the spec:

Schema Component Constraint: Type Derivation OK (Simple)

For a simple type definition (call it D, for derived) to be validly derived
from a simple type definition (call this B, for base) given a subset of
{extension, restriction, list, union} (of which only restriction is actually
relevant) one of the following must be true:

1 They are the same type definition.

2 All of the following must be true:

2.1 restriction is not in the subset, or in the {final} of its own
	{base type definition};

2.2 One of the following must be true:
2.2.1 D's ·base type definition· is B.
2.2.2 D's ·base type definition· is not the ·simple ur-type definition· and
	is validly derived from B given the subset, as defined by this constraint.
2.2.3 D's {variety} is list or union and B is the ·simple ur-type
definition·.
2.2.4 B's {variety} is union and D is validly derived from a type definition
in
	B's {member type definitions} given the subset, as defined by this
constraint.

Part 2 Section 2.5.1.3
"The order in which the ·memberTypes· are specified in the definition (that
is, the order of the <simpleType> children of the <union> element, or the
order of the QNames in the memberTypes attribute) is significant. During
validation, an element or attribute's value is validated against the
·memberTypes· in the order in which they appear in the definition until a
match is found. The evaluation order can be overridden with the use of
xsi:type.

Part 1 Section 2.6.1 xsi:type
The Simple Type Definition (§2.2.1.2) or Complex Type Definition (§2.2.1.3)
used in ·validation· of an element is usually determined by reference to the
appropriate schema components. An element information item in an instance
may, however, explicitly assert its type using the attribute xsi:type. The
value of this attribute is a ·QName·; see QName Interpretation (§3.15.3) for
the means by which the ·QName· is associated with a type definition.

P1 S 3.3.1
"The supplied values for {disallowed substitutions} determine whether an
element declaration appearing in a ·content model· will be prevented from
additionally ·validating· elements (a) with an xsi:type (§2.6.1) that
identifies an extension or restriction of the type of the declared element,
and/or (b) from ·validating· elements which are in the substitution group
headed by the declared element. If {disallowed substitutions} is empty, then
all derived types and substitution group members are allowed.

3.3.4 Element Declaration Validation Rules
Governed by item 4 of Validation Rule: Element Locally Valid (Element)
Validation Rule: Schema-Validity Assessment (Element)

Received on Friday, 14 June 2002 11:18:50 UTC