Re: [XQuery] MS-XQ-LC1-124

Michael Rys wrote:

> Jonathan wrote:
>
>>Because elements are the only complex structure available to XQuery,
>>    
>>
>and
>  
>
>>when queries get large and complex, they need to be able to pass
>>    
>>
>complex
>  
>
>>structures around. It's like asking whether an object oriented program
>>should construct an object that is known to conform to its class
>>declaration by default, or whether C should create a struct that
>>actually conforms to its declaration by default. When the definition
>>    
>>
>of
>  
>
>>an element has been imported, by default, the elements that are
>>    
>>
>created
>  
>
>>should conform to that definition.
>>    
>>
>
>[Michael Rys] You can achieve that functionality by explicitly setting
>your validation mode to strict. The issue is that many XML applications
>want to do validation as late as possible. Forcing XQuery
>implementations to do so during every construction per default is the
>wrong design (make more costly operations use explicit syntax).
>  
>
There is some merit to that argument. But another principle is that the 
default behavior should not be surprising. Suppose the default mode is 
skip. I find it suprising that the following query would raise an error:

   import schema "invoice.xsd";
 
   declare function total($i as element(my:invoice))
     as xs:integer
   {
      sum ($i//product/price)
   };

   let $t := <invoice>
               <customer>Wile E. Coyote</customer>
               <items>
                 <item>
                   <name>Atomic Hammer</name>
                   <price>13.45</price>
                 </item>
                 <item>
                   <name>Rocket Skates</name>
                   <price>45.23</price>
                 </item>
               </items>
             </invoice>
   return total($t)

I don't like your 'global' solution either, because the most important 
reason for SequenceType is stating the types of function  arguments and 
returns. It is rarely useful to specify that a function's argument be 
"any element whose element name is 'invoice', no matter what that 
element contains".  For instance, in the above query, what really 
matters to the function it that it knows how to find the price elements 
within an invoice element - it is written based on assumptions about the 
structure of the element, and the current element(my:invoice) makes 
precisely the right guarantees.

You suggest that we add more syntax to SequenceType (probably a bad idea 
in general!) to distinguish the following cases:

    element(my:invoice) - any element named my:invoice
    element(global my:invoice) - a valid my:invoice element, as defined 
in the ISSD

I don't like that idea for a number of reasons:

1. Adding one more distinction to SequenceType is confusing for the 
user. I do not know enough important use cases for function parameters 
that specify the name of the element to make this the default for 
element parameters. This can already be expressed in our current 
syntax:  element(my:invoice, xs:anyType)
2. There's no simple keyword that seems to suggest 'a valid element 
named my:invoice, as opposed to any element that simply has that name'. 
Your suggestion to use 'global' for that is an indication of the problem.
3. On average, about 80% of elements and attributes in schemas are 
locally declared, and 'global' implies not supporting valid, but locally 
declared elements using SequenceType.

So I think this would be a bad idea.

Jonathan

Received on Wednesday, 18 February 2004 07:34:09 UTC