RE: [dom-xpath] XPath or? (was RE: Announcing www-dom-xpath@w3.or g)

Miles Sabin <msabin@cromwellmedia.co.uk> wrote:
> Delegating queries to DOM
> implementations allows them to be resolved using internal
> information which is simply not available via the public API.

Well, I may be bowing to your superior intellect.  Here's an argument for
your side:

void foo(Node n1, Node n2)
{
   NodeIterator n1i = ((XPath)n1).locate("name/address", ...); // uses your
implementation
   NodeIterator n2i = ((XPath)n2).locate("name/address", ...); // uses my
implementation
   ...
}

i.e. in this case, the method didn't know or care which implementation it
was using.  Using an external implementations would make this harder, as
you would have to match the Node implemenation to the XPath implementation.

Ugh.  I'm not trying to be argumentative for the fun of it.  I really think
the DOM as a monster set of foundation classes is a mistake.  But, yes, I
guess there are tradeoffs.

You could have something like:

DOMImplementation impl = node.getOwnerDocument().getImplementation();
// Make up a "getFeature" function that would return an interface.
ExpressionFactory factory = (ExpressionFactory )impl.getFeature
("http://www.w3.org/TR/xpath", null);
if(null != factory )
{
   Expression expr= factory.create("name/address");
   NodeIterator n1i = expr.execute(node, exprContext);
   ...
}

Which is way ugly.  As compared to:

DOMImplementation impl = node.getOwnerDocument().getImplementation();
if(impl .hasFeature("http://www.w3.org/TR/xpath", null))
{
  NodeIterator n1i = ((Expression)node).findNodes("name/address",
exprContext);
  ...
}

I guess I could live with this (i.e. the second one).  I suppose an XPath
implementation could do something like:

Expression expr = new XPathImpl(node, "name/address");
NodeIterator n1i = expr.findNodes("name/address", exprContext);

...which would allow looser coupling with the DOM implementation, and allow
compatibility with DOM1 implementations.

-scott

Received on Wednesday, 3 May 2000 15:44:32 UTC