This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 5472 - [XQuery 1.1] Requirement: validation by type
Summary: [XQuery 1.1] Requirement: validation by type
Alias: None
Product: XPath / XQuery / XSLT
Classification: Unclassified
Component: XQuery 3.0 (show other bugs)
Version: Working drafts
Hardware: PC Windows XP
: P2 normal
Target Milestone: ---
Assignee: Jonathan Robie
QA Contact: Mailing list for public feedback on specs from XSL and XML Query WGs
Depends on:
Reported: 2008-02-11 11:32 UTC by Michael Kay
Modified: 2013-06-19 07:32 UTC (History)
0 users

See Also:


Description Michael Kay 2008-02-11 11:32:46 UTC
I am raising this requirement on behalf of a Saxonica customer. Saxon implements a pragma that allows type-based validation. This user is making extensive use of the facility, which they find invaluable for processing FpML documents in particular, and they have asked me to propose adding it to the language.

Syntax for the facility might be something like

"validate" "as" type-name { Expr }

The effect is to validate Expr as an instance of the specified simple or complex type (which must be a type defined in the static context). Detailed semantics should be the same as validation-by-type in XSLT 2.0, see

(The XSLT 2.0 capability allows validation of attributes, as well as elements. This is useful, but not essential).

There are two main use-cases for this facility:

(a) where the vocabulary design places heavy reliance on xsi:type to distinguish different document types using the same element names (as is the case with FpML)

(b) where the schema makes extensive use of local element declarations with global types: in this situation validation based on the element name alone is not possible.

Note that as far as XML Schema is concerned, specifying a type name rather than an element name as the parameter driving validation is very much a recognized part of the specification.

Some use cases can be achieved by specifying "validate lax" and putting an xsi:type attribute on the element to be validated. However, this doesn't have equivalent semantics in all cases; in some cases the xsi:type attribute might be unwanted or disallowed by a DTD; and it doesn't lend itself readily to static type-checking.
Comment 1 Jonathan Robie 2008-04-01 16:51:46 UTC
We agreed to add this to the existing validate expression:

[63]    	ValidateExpr 	   ::=    	"validate" ValidationMode? TypeSpec? "{" Expr "}"
[63a]		TypeSpec	   ::=		"as" QName
[64]    	ValidationMode 	   ::=    	"lax" | "strict"
Comment 2 Michael Kay 2008-04-01 22:26:44 UTC
Glad to see this get WG approval - the customer who asked for it will be delighted.

However, I would expect

[63]  ValidateExpr  ::=  "validate" (ValidationMode | TypeSpec)? "{" Expr "}"

as I don't think it's meaningful (in terms of validation options defined in XML Schema) to specify both a validation mode and a type.
Comment 3 Jonathan Robie 2008-11-03 16:17:28 UTC
This is supported in the new internal editorial draft.