Schema Validation and Type Assignment
Adding a schema to the ISSD does not automatically cause any input documents or result XML to be validated or annotated with types. There are two occasions during query evaluation when schema validation may occur:
The first is when an input document is opened, for example using the doc
or collection
function. Depending on the implementation, the processor may validate the input document at this time. However, a processor is not required to automatically validate input documents, even if it supports XML Schema. It can choose the way it finds and selects schemas for the input document. Additionally, the processor is not required to stop evaluating the query if an input document is found to be invalid but still well formed. You should consult the documentation for your XQuery implementation to determine how it handles these choices.
If you're relying on an input document being prevalidated in this way, it's a good idea to declare this. For example you can write:
declare variable $in as document-node(schema-element(catalog)) := doc("catalog.xml");
This causes the query to fail if the validation hasn't been done (or if validation failed). It also tells the query compiler what the expected type of $in
is, which is useful information for optimization and error checking.
If an input document is validated, the definitions used must be consistent with any definitions added to the ISSD. For example, if your input document is a catalog.xml
document that was ...
Get XQuery now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.