W3C home > Mailing lists > Public > www-dom@w3.org > July to September 2003

DOM L3 Node.compareDocumentPosition

From: Curt Arnold <carnold@houston.rr.com>
Date: Thu, 31 Jul 2003 23:04:52 -0500
Message-ID: <3F29E6E4.7000706@houston.rr.com>
To: WWW DOM <www-dom@w3.org>

As mentioned in a previous message, the correspondence between the 
DocumentPosition bits and XPath axes is unclear and use different names 
(CONTAINED_BY vs Ancestor, for example) for the same concept.

I would think that Node.compareDocumentPosition would be very prone to 
usage errors.  Most scripting languages would not provide symbolic 
constants and it would be relatively easy to misuse bit-wise operators.

It would seem a whole lot simplier and more usable to provide boolean 
methods that correspond to the XPath Axes,

boolean isChild(Node node);
boolean isDescendant(Node node);
boolean isParent(Node node);
boolean isAncestor(Node node);
boolean isFollowingSibling(Node node); // always false for attribute
boolean isPrecedingSibling(Node node);  // always false for attributes
boolean isSibling(Node node);
boolean isFollowing(Node node);
boolean isPreceding(Node node);
boolean isAttribute(Node node);

Plus the existing isSame(Node node) for the self axis.  
descendant-or-self and ancestor-or-self could be handled by or'ing 
isSame and the appropriate other axis test.

Adding a method to determine if the nodes are in the same document might 
also be helpful.

If you are only interested if the particular pair are, for example, 
parent and child, it should be more efficient to only check that instead 
of figuring out how they are related.
Received on Friday, 1 August 2003 00:04:57 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Friday, 22 June 2012 06:13:57 GMT