Re: DOM L3 XPath: Multiple matching nodes when number, string or boolean type

At 9:55 PM -0600 2/16/02, Curt Arnold wrote:


>This was specifically in the context of the DOM L3 XPath, not XPath in
>general.  Specifying a return type on the evaluate call requires a coercion,
>however the how the coercion is done is not as specifically detailed in the
>DOM L3 XPath draft as the number(), string() and boolean() functions are in
>XPath.
>
>Specifically, what should happen if you do:
>
>XPathResult result = ((XPathEvaluator) doc).evaluate("/svg/rect/@width",
>doc,null, NUMBER_TYPE, null);
>
>I do not believe the DOM L3 XPath draft clearly stated what the expected
>behavior should be for this case.

Yuck. I had no idea you could do that. You're right. That is a real 
issue. My reading of the WD is that this would have the same effect 
as using number() or boolean() or string() on a node-set; that is, it 
returns the typed value of the first node and ignores the rest.

I suggest, however, that this functionality be dropped from DOM Level 
3 XPath. I don't think it lets developers do anything they can't 
already do with XPath functions. Dropping the in unsigned short type 
argument from evaluate() would simplify the API. I prefer a cleaner 
division between what's done in XPath and what's done in DOM.

On a related matter, I also think the earlier proposal to drop the in 
XPathResult result argument is also a good idea. This would reduce 
the number of arguments from 5 to 3, only one of which is optional 
(i.e. can be null). This seems much cleaner and much easier to teach 
and explain while not removing any significant functionality.
-- 

+-----------------------+------------------------+-------------------+
| Elliotte Rusty Harold | elharo@metalab.unc.edu | Writer/Programmer |
+-----------------------+------------------------+-------------------+
|          The XML Bible, 2nd Edition (Hungry Minds, 2001)           |
|              http://www.ibiblio.org/xml/books/bible2/              |
|   http://www.amazon.com/exec/obidos/ISBN=0764547607/cafeaulaitA/   |
+----------------------------------+---------------------------------+
|  Read Cafe au Lait for Java News:  http://www.cafeaulait.org/      |
|  Read Cafe con Leche for XML News: http://www.ibiblio.org/xml/     |
+----------------------------------+---------------------------------+

Received on Sunday, 17 February 2002 10:57:31 UTC