[xquery-talk] Top N Most Common Mistakes [SEC=UNCLASSIFIED]

Michael Kay mike at saxonica.com
Wed Aug 15 02:25:07 PDT 2007


> 
> By this, Michael, do you mean anything more than "use named 
> types rather than anonymous types" in your Schemas? If so, 
> can you elaborate on what "properly" means here?

To get compile time checking of your query against a schema, you need to
declare the types of variables and of arguments to functions. You also need
to ensure that the expected type of the context item and of the result of
doc() is known statically. This is best done by defining global variables,
for example

declare variable $in as document-node(schema-element(purchase-order)) :=
(/);
declare variable $books as document-node(schema-element(booklist)) := :=
doc('books.xml');

declare function f:orders-for-customer($c as schema-element(customer)) as
schema-element(order)* {
  ...
}

When you write a path expression and the type of the first step in the path
is known, Saxon-SA will give you warnings if any subsequent steps are
incapable of selecting any nodes.

Using named types in your schemas is useful because it allows you to refer
to them in your queries - but there's no benefit unless you actually do
refer to them!

Michael Kay
http://www.saxonica.com/  



More information about the talk mailing list