RE: [XQuery] Semantics of validation context

> I am having trouble understanding the meaning of the 
> validation context which may be specified in a validate 
> expression (and equally, the implicit validation context used 
> when validating element constructors)

Responding to my own comment, here are some of the rules I have guessed
at, which need to be explained in the specification. This is a
quickly-written first draft, but I think it illustrates some of the
rules that are currently missing.


Definition: a validation context is either global, or a compositor, or
void. If it is a compositor then it corresponds to a sequence, choice,
or all compositor in a schema.

We define a function that takes as input a validation context and an
element name, and returns as output an element declaration; it returns a
type error if no element declaration can be found.

If the context is global, then this function looks for a global element
declaration with the required name.

If the context is void, then this function always returns a type error.

If the context is a compositor, then the function searches the particles
that make up the compositor, searching recursively through any
subordinate compositors or named groups, to find a particle that is an
element declaration with the required name. It returns that element
declaration, or raises in error if none can be found. Wildcard particles
are ignored in performing this search.

Given an element declaration, we define a function that returns a
validation context for the contents of that element. If the element has
a simple type, the validation context is void. If the element has a
complex type, the validation context is the compositor representing the
content model of the element. If the complex type is defined by
extension, this compositor is a synthetic one representing a sequence
consisting of the content model for the base type followed by the
content model for the extension.

When a direct element constructor or a computed element constructor with
a literal name is processed, the validation context for the
subexpressions of the constructor is obtained by using the first
function to find an element declaration given the outer validation
context and the element name, and then using the second function to find
the inner validation context for this element declaration. It is a
static error if no element declaration can be located; it is not an
error if the resulting validation context is void (it only becomes an
error if this validation context is actually used for validating an
element).

Within a validate expression, a SchemaContextPath is evaluated as
follows. If the first component is an element name, then there must be a
global element declaration with that name, and the initial validation
context is established by applying the second function to this element
declaration. If the first component is a type, then it must be a global
complex type definition, and the intiial validation context is the
compositor representing the content model of this type. For subsequent
steps in the path, the validation context is obtained by applying the
two functions to the validation context obtained for the previous step,
together with the named element; it is a static error if the first
function finds no element declaration. It is an error if the final
validation context or any intermediate validation context is void.

Michael Kay

Received on Tuesday, 20 January 2004 11:00:35 UTC