Spurious warning about optional field in xs:key
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:complexType name="item" final="#all">
<xs:attribute name="id" type="xs:string" use="required"/>
<xs:attribute name="index" type="xs:positiveInteger" default="1"/>
and here is a sample instance document:
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?
#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.