'Why does XML Schema permit declaring an element as nillable and fixed?
XML Schema allows for an element to be declared as both nillable and fixed. For example:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="nilTest" type="xs:integer" nillable="true" fixed="5" />
</xs:schema>
However, given the following document as input:
<nilTest xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true" />
parsing (with validation enabled) will fail (e.g. message from Xerces parser):
cvc-elt.3.2.2: There must be no fixed {value constraint} for element 'nilTest', because 'http://www.w3.org/2001/XMLSchema-instance,nil' is specified.
I'm curious why declaring the Schema this way, i.e. with an element that is both fixed and nillable, is permitted.
Solution 1:[1]
"Why" questions are always difficult, because even people who were involved in the design sometimes have difficulty explaining the process by which a decision was reached. (I wasn't involved until later.)
Saxon, incidentally, agrees with Xerces in its handling of this case: the schema is considered valid, and the instance is considered invalid.
It's entirely possible that the schema WG never considered this question. It's also possible that they considered it, and decided it wasn't worth adding another rule; I certainly remember cases where they considered adding a rule to stop you writing "ineffable" schemas (schemas against which no document can be valid) and decided that the extra rule wasn't needed.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Michael Kay |
