Re: "Unsafe" union?
Michael Kay <[email protected]> Tue, 16 Oct 2012 15:15:17 +0100
| Newsgroups | gmane.text.xml.schema.devel |
|---|---|
| Message-ID | <[email protected]> |
The principle of type safety is the rule that if X is substitutable for Y (i.e. an instance of type X can be supplied where an instance of type Y is expected), then every valid instance of X must be a valid instance of Y. if you define a union type U as union of xs:date and xs:dateTime, then xs:date and xs:dateTime are substitutable for U: for example an element of type xs:date can safely be a member of the substitution group of an element of type U because every instance of xs:date is a valid instance of U. However, if you define another union type V as a restriction of U, with the constaining facet <pattern value="20.*]"/>, then not every xs:date is a valid instance of V (specifically, dates outwith the 21st century are not). However, XSD 1.0 incorrectly treats xs:date as being substitutable for V, which means that a program expecting to process 21st century dates might find itself with a date from a different century on its hands. XSD 1.1 fixes this error, and XPath 3.0 incorporates this fix. Michael Kay Saxonica On 16/10/2012 12:08, Costello, Roger L. wrote: > > Hi Folks, > > The XPath 3.0 specification has this statement: > > The current (second) edition of > > XML Schema 1.0 contains an error > > in respect of the substitutability of > > a union type by one of its members: > > it fails to recognize that this is unsafe > > if the union is derived by restriction > > from another union. > > Huh? > > What is "unsafe"? > > What is that saying please? > > The XPath 3.0 specification then says: > > This problem is fixed in XSD 1.1, but > > the effect of the resolution is that an > > atomic value labeled with an atomic type > > cannot be treated as being substitutable > > for a union type without explicit validation. > > Again, what is that saying please? > > /Roger >