Project

Profile

Help

Bug #1998

Spurious warning about optional field in xs:key

Added by Michael Kay about 2 years ago. Updated about 2 years ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
Diagnostics
Sprint/Milestone:
-
Start date:
2014-02-06
Due date:
% Done:

100%

Spent time:
-
Legacy ID:
Applies to branch:
Fix Committed on Branch:
Fixed in Maintenance Release:
Found in version:
9.5
Fixed in version:
9.5.1.5

Description

From the saxon-help list:

The problem that I am having is that I cannot determine if Saxon is giving me a spurious warning or whether there is actually something wrong with my schema. Here's a stripped down version of the schema that exhibits the problem:


<xs:schema
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:items="file://localhost/items"
version="1.1"
elementFormDefault="qualified"
targetNamespace="file://localhost/items">

&lt;xs:complexType name="item" final="#all"&gt;
&lt;xs:attribute name="id" type="xs:string" use="required"/&gt;
&lt;xs:attribute name="index" type="xs:positiveInteger" default="1"/&gt;
&lt;/xs:complexType&gt;
&lt;xs:element name="items"&gt;
&lt;xs:complexType&gt;
&lt;xs:sequence&gt;
&lt;xs:element
name="item"
type="items:item"
minOccurs="0"
maxOccurs="unbounded"/>
&lt;/xs:sequence&gt;
&lt;/xs:complexType&gt;
&lt;xs:key name="item-id"&gt;
&lt;xs:selector xpath="items:item"/&gt;
&lt;xs:field xpath="@id"/&gt;
&lt;xs:field xpath="@index"/&gt;
&lt;/xs:key&gt;
&lt;/xs:element&gt;

</xs:schema>

and here is a sample instance document:


<items
xmlns="file://localhost/items"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="file://localhost/items items.xsd">

&lt;item id="A"/&gt;

</items>

Saxon keeps issuing this warning:

Warning: on line 27 of items.xsd:
The field expression may select no nodes, which would make the instance document invalid

Which I assume has something to do with the use of the index attribute which is non-required and has a default value. I have tried all sorts of ways to try to make an invalid instance document, but all that happens is this warning.

Is something wrong with what I am doing? Is it just a Saxon quirk?

Regards,
Paul Mensonides

History

#1 Updated by Michael Kay about 2 years ago

  • Status changed from New to In Progress

The spec in this area is pretty ropey (as is often the case with XSD). It says in 3.11.4 rule 1 "A data model instance is constructed from the input information set, as described in [XDM]. ", but it doesn't say which part of XDM it is referring to: is it construction from an Infoset, or construction from a PSVI? The fact that it says "input information set" suggests the former, as does the fact that this operation is part of validation, so the PSVI doesn't yet exist. If it really were from the infoset, then default values for attributes would not be present. But the spec goes on to say that it uses the [schema actual value] of the nodes, which is a concept that doesn't even exist in XDM! And in the Note, it confirms that default values "may" be used, which I guess one should read as meaning that they must be used if they are present. At any rate, Saxon does use the default value when it actually evaluates the constraint, so the static validation of the schema that produces this warning should take this into account, and not produce the warning if there is a default or fixed value.

#2 Updated by Michael Kay about 2 years ago

  • Status changed from In Progress to Resolved

A patch has been committed on the 9.5 and 9.6 branches.

#3 Updated by O'Neil Delpratt about 2 years ago

  • Status changed from Resolved to Closed
  • % Done changed from 0 to 100
  • Fixed in version set to 9.5.1.5

Bug fix applied in Saxon maintenance release 9.5.1.5

Also available in: Atom PDF