Re: document is not an element, is it?

Jonathan Robie wrote:

> At 05:35 PM 3/10/2003 -0500, Todd A. Mancini wrote:
>
>> >At 06:04 PM 3/9/2003 +0100, MW wrote:
>> >>Hi Jonathan!
>> >>
>> >>In the working draft "XQuery 1.0: An XML Query Language" in chapter
>> "4.5
>> >>Function Definitions" there is this example:
>> >>define function depth($e as element) as xs:integer
>> >>{
>> >>   {-- An empty element has depth 1 --}
>> >>   {-- Otherwise, add 1 to max depth of children --}
>> >>   if (empty($e/*)) then 1
>> >>   else max(for $c in $e/* return depth($c)) + 1
>> >>}
>> >>depth(document("partlist.xml"))
>> >>
>> >>But this function does not run in GALAX. And I think it is obvious
>> that
>> >>the function must not work, because the funktion-parameter is declared
>>
>> >>as  "element", but it is called with a parameter of type "document". I
>>
>> >>think the declaration must be changed  from "element" to "item".
>>
>> >Right, that's a bug in the spec.
>>
>> Just to keep everything clear, and I cannot speak for GALAX, but isn't
>> 'node*' the return type of the document() function, not the 'document'
>> type?  The 'document' type results from computed document constructors,
>> not calls to the document() function.
>
The document function is defined in "XQuery 1.0: An XML Query Language"
as follows:
"The fn:document function, when its first argument is a string
containing a single URI that refers to an XML document, converts that
document to a Data Model representation and returns its document node."
So I was (and still am) assuming that the return type of the document()
function is of  type 'document' and not 'element', since the document
node is not a element node, is it?

>
> But the document node is also the root of every document, presumably 
> also of PARTLIST.XML.
>
>> Furthermore, would it not be a static type error to rewrite the function
>> so that the argument type is 'item' rather than 'element', as was
>> suggested?  'node*' is not a subtype of 'item' (but 'item*' would be
>> valid, as would, of course, 'node*', which is what I would recommend for
>> the argument type).
>
I am a real XQuery-beginner, so I have to cite "XQuery 1.0: An XML Query
Language" again:
"- node* refers to a sequence of zero or more nodes of any type
  - item* refers to a sequence of zero or more nodes or atomic values"
Isn't 'item' the supertype of 'node' and 'atomic value'? If it is, there
should be no static error when using "item" because document() returns
exactly one document node (see my comment above).
Nevertheless I partly agree with you. I think the argument type should
be 'node' - as it is more special than 'item'.
Please correct me, if I am wrong.

   - Michael W.

>
> I wasn't thinking of the static type - I agree that node* is best.
>
> Jonathan
>

Received on Tuesday, 11 March 2003 12:20:30 UTC