RE: abstract elements and xsi:type substitution

Currently both system.xml and MSXML go through the 1.2 clause and accept the xml instance as valid.  We had a few discussions on this along the lines of Michael's response and some of us think that the _intent_ of the spec was not to allow abstract elements in the instance documents regardless of xsi:type (as Sandy commented).  So we wanted to see what others thought.

 

Anybody else wants to comment on the _intent_ of the spec?

 

Stan

 

--------------------------------------

Stan Kitsis,

Webdata - XML

Microsoft Corporation

--------------------------------------

 

________________________________

From: xmlschema-dev-request@w3.org [mailto:xmlschema-dev-request@w3.org] On Behalf Of Michael Kay
Sent: Wednesday, January 11, 2006 2:01 AM
To: Stan Kitsis; xmlschema-dev@w3.org
Subject: 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 ·valid· <http://www.w3.org/TR/xmlschema-1/#key-vn>  with respect to an element declaration all of the following must be true: 

1 The declaration must not be ·absent· <http://www.w3.org/TR/xmlschema-1/#key-null> .

2 Its {abstract} <http://www.w3.org/TR/xmlschema-1/#e-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 Schema-Validity Assessment (Element) (§3.3.4) <http://www.w3.org/TR/xmlschema-1/#cvc-assess-elt>  with no stipulated declaration or definition, and either ·strict· <http://www.w3.org/TR/xmlschema-1/#key-sva>  or ·lax· <http://www.w3.org/TR/xmlschema-1/#key-lva>  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 1.1 <http://www.w3.org/TR/xmlschema-1/#c-ed>  above holds clause 1.2 <http://www.w3.org/TR/xmlschema-1/#c-td>  does not, and vice versa. When an xsi:type [attribute] <http://www.w3.org/TR/xml-infoset/#infoitem.element>  is involved, however, clause 1.2 <http://www.w3.org/TR/xmlschema-1/#c-td>  takes precedence, as is made clear in Element Locally Valid (Element) (§3.3.4) <http://www.w3.org/TR/xmlschema-1/#cvc-elt> ." This note isn't as helpful as one would like, however, because Element Locally Valid (Element) <http://www.w3.org/TR/xmlschema-1/#cvc-elt> 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 Thursday, 12 January 2006 22:15:44 UTC