RE: abstract elements and xsi:type substitution

This is what Saxon says on the matter:
 
Validation error on line 9 column 32 of file:/c:/temp/test.xml:
  Invalid element <Item>: the element is declared to be abstract
Validation of source document failed
 
However, the schema spec doesn't give you a simple boolean function
isValid(instance, schema). For example in 3.3.4 Element Locally Valid
(Element) we read:
 
For an element information item to be locally
<http://www.w3.org/TR/xmlschema-1/#key-vn> ·valid· with respect to an
element declaration all of the following must be true: 
1 The declaration must not be  <http://www.w3.org/TR/xmlschema-1/#key-null>
·absent·.
2 Its  <http://www.w3.org/TR/xmlschema-1/#e-abstract> {abstract} must be
false.
3 ...
 
So it's clear that your Item element is not locally valid with respect to
this element declaration.
 
But from 3.3.4 Element Locally Valid (Type) we can see that the element is
locally valid with respect to the type xs:string.
 
In 5.2 we see that there are three ("primary") ways of assessing the
schema-validity of an element. Method 1 allows you to ask "is Item a valid
xs:string", and the answer is yes. Method 2 allows you to ask "is Item a
valid Item", and the answer is no. Method 3 allows you to ask "is Item
valid?" - which is closest to your question, and what the spec says is:
 
"The processor starts from
<http://www.w3.org/TR/xmlschema-1/#cvc-assess-elt> Schema-Validity
Assessment (Element) (§3.3.4) with no stipulated declaration or definition,
and either  <http://www.w3.org/TR/xmlschema-1/#key-sva> ·strict· or
<http://www.w3.org/TR/xmlschema-1/#key-lva> ·lax· assessment ensues,
depending on whether or not the element information and the schema determine
either an element declaration (by name) or a type definition (via xsi:type)
or not."
 
Schema-Validity Assessment (Element) clause 1 says that "for schema-validity
to be assessed", *either* 1.1 or 1.2 must be true. 1.1 is true if the
element is valid against the element declaration; 1.2 is true if it is valid
against the xsi:type. This suggests that the element has to be valid against
either the element declaration or the xsi:type, but not necessarily against
both.
 
What's more, there's a note: "Note: In general if clause
<http://www.w3.org/TR/xmlschema-1/#c-ed> 1.1 above holds clause
<http://www.w3.org/TR/xmlschema-1/#c-td> 1.2 does not, and vice versa. When
an xsi:type  <http://www.w3.org/TR/xml-infoset/#infoitem.element>
[attribute] is involved, however, clause
<http://www.w3.org/TR/xmlschema-1/#c-td> 1.2 takes precedence, as is made
clear in  <http://www.w3.org/TR/xmlschema-1/#cvc-elt> Element Locally Valid
(Element) (§3.3.4)." This note isn't as helpful as one would like, however,
because  <http://www.w3.org/TR/xmlschema-1/#cvc-elt> Element Locally Valid
(Element) says that the element is invalid if the element declaration
specifies "abstract", regardless of xsi:type - in other words, the element
declaration, in this respect at least, actually takes precedence over
xsi:type!
 
It's all pretty murky. Saxon has decided the issue one way, which I think is
the common-sense way, but I think one could take a different interpretation.
 
Interesting question.
 
Michael Kay
http://www.saxonica.com/
 
 
  _____  

From: xmlschema-dev-request@w3.org [mailto:xmlschema-dev-request@w3.org] On
Behalf Of Stan Kitsis
Sent: 11 January 2006 00:21
To: xmlschema-dev@w3.org
Subject: abstract elements and xsi:type substitution



Is the following valid? Why or why not?

 

Thanks,

Stan Kitsis

 

******* XSD **************

 

<?xml version="1.0" encoding="utf-8" ?> 

<xs:schema targetNamespace="foo"

                  elementFormDefault="qualified"

                  xmlns="foo"

                  xmlns:xs="http://www.w3.org/2001/XMLSchema">

  

  <xs:element name="Item" type="xs:string" abstract="true"/>

</xs:schema>

 

******* XML **************

<?xml version="1.0" encoding="utf-8"?>

<Item xmlns="foo" 

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

      xmlns:xs="http://www.w3.org/2001/XMLSchema"

          xsi:type="xs:string">text</Item>

Received on Wednesday, 11 January 2006 10:01:45 UTC