W3C home > Mailing lists > Public > www-dom@w3.org > October to December 2001

DOM Xpath comments (elaboration)

From: Arnold, Curt <Curt.Arnold@hyprotech.com>
Date: Thu, 1 Nov 2001 14:00:40 -0700
Message-ID: <70E215722F6AD511820A000103D141D40AA64B@thor.aeathtl.com>
To: "'www-dom@w3.org'" <www-dom@w3.org>
There were a few typos in the previous message, said "optionally execute" when I meant "optimally execute".  The "prevents" in "This prevents either requires" is spurious.

A benefit of collapsing the evaluate() + getSetSnapshot() or evaluate() + getSetIterator() sequence into a single evaluate call is to eliminate a set of edge cases where multiple calls are made to
getSetSnapshot() or getSetIterator() after one evaluate() call.

For example, you could:

XPathResult result = xpath.evaluate(contextNode, XPathResult.NODE_SET,null);
//    start a unordered iterator
XPathSetIterator iter1 = result.getSetIterator(false);
Node node1 = iter1.nextNode();
//    restart iteration from the top
//    may encourage the implementation to cache the results from
//    the previous incremental evaluation or
//    might force evaluation of the query again
XPathSetIterator iter2 = result.getSetIterator(false);
Node node2 = iter2.nextNode();

//    Now do an ordered snapshot
//       probably requires another evaluation
XPathSetSnapshot snap1 = result.getSetSnapshot(true);

//    do a simultaneous ordered iteration
//       probably has to reexecute the query
XPathSetIterator iter3 = result.getSetIterator(true);
Node node3 = iter3.nextNode();

Collapsing XPathSetIterator and XPathSetSnapshot into XPathResult eliminates all these edge cases that might trigger multiple evaluations of the query.  If you requested an Iterator, you would get a
forward-only, once-through iterator, if you wanted to start over you would need to explicitly request a second evaluation.


Look up the namespace URI associated to the given namespace prefix. The XPath evaluator must never call this with a null or empty argument, because the result of doing this is undefined. 

Leaving it undefined is just asking for interoperability problems.  I understand that the behavior of the equivalent function in Node might be in flux, however both should define a consistent
Received on Thursday, 1 November 2001 16:03:19 UTC

This archive was generated by hypermail 2.3.1 : Tuesday, 20 October 2015 10:46:09 UTC