Improving DOM Traversal and DOM XPath

Hi All,

Since we're taking a look at DOM-Core and fixing some of the old-cruft
in it, I have some suggestions for making some of the functions on
document easier to use. These functions aren't technically defined as
part of DOM-Core, but they are functions on the Document object which
is defined by DOM-Core.

First off is document.createTreeWalker and
document.createNodeIterator. They have the same signature which
currently is:

document.createX(root, whatToShow, filter, entityReferenceExpansion);

Given that entity references are being removed, we should simply
remove the last argument. Note that this is a backwards compatible
change since additional arguments to any DOM function are just ignored
in all browsers I think. Additionally, I see no reason to keep the
'filter' argument required as it's quite common to leave out.

We could even make the whatToShow argument optinal and default it to
SHOW_ALL. Originally I was going to propose that we default it to
SHOW_ELEMENTS as I had thought that that would be a common value,
however it appears that SHOW_TEXT is as, if not more, commonly used.
The downside to defaulting to SHOW_ALL is that people might use the
default and then do filtering manually, which is slower than having
the iterator/treewalker do the filtering.

I'd like to give some DOM XPath a similar treatment. The following
three functions could be simplified:

XPathEvaluator.createExpression(expression, resolver);
Here I think we can make the 'resolver' argument optional as
namespaces are commonly not used on the web.

XPathEvaluator.evaluate(expression, contextNode, resolver, type, result);
We can make 'resolver', 'type' and 'result' optional. 'type' would
default to ANY_TYPE(0) and the other two to null.

XPathExpression.evaluate(contextNode, type, result);
Here all but the first could be optional. The defaults would be the
same as for XPathEvaluator.evaluate.

I'd like to make these changes to firefox, but first I wanted to hear
what people here think. I know we don't have editors for the relevant
specs, but I think we can make an informal decision that these changes
sound good if people think they are.

/ Jonas

Received on Monday, 25 April 2011 18:32:38 UTC