W3C home > Mailing lists > Public > public-webapps@w3.org > April to June 2011

Improving DOM Traversal and DOM XPath

From: Jonas Sicking <jonas@sicking.cc>
Date: Mon, 25 Apr 2011 11:31:40 -0700
Message-ID: <BANLkTi=DPjiNWZHtvLWhEp_cr=J86iZS=g@mail.gmail.com>
To: Webapps WG <public-webapps@w3.org>
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

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 18:13:19 UTC