RE: generating XPath expression from Node for DOM L3 XPath

> Joseph Kesselman [mailto:keshlam@us.ibm.com] wrote:
> I agree with the observation that most XPath implementations should
> probably come with XPath generator utilities.
>
> But it may be unclear whether it really should be a DOM API 
> as opposed to a
> utility running on top of the DOM APIs. Unlike XPath, where 
> we have all the
> incrementality/invalidation concerns, this might want to be a
> run-it-once-and-get-a-string operation.

You'll need both a string and some representation of namespace prefix/uri mapping.  Hence, the reason the method returned an XPathExpression, not a String.  If the node is in a out of process
implementation, then it could be really expensive to walk the tree to generate the XPath.

> >it would be left up to the individual implementor to choose 
> the algorithm
> to
> >build the XPath
> 
> Testability would be awful, and portability would be bad if folk make
> assumptions about the quality of the XPath generated (eg, how 
> likely it is
> to be broken by trivial document mutation -- city[2] is 
> likely to be a lot
> stronger than the more generic "fifth child", for example, 
> even if both
> were valid when they were calculated).

You would always have the identity that if you evalute the XPath you should get the same node back.  That symmetry could actually help the testability of the XPath evaluatation since you could run
through all the nodes of a document, generate the XPath query and then evaluate the query and test for identity.

Unfortunately, you can not build a durable XPath expression without having some concept of the nature of the document and what are significant and insignificant changes.  Definitely, all that you
could ever promise was that the XPath identified the node at the moment of creation.

It would be possible to define a specific algorithm for generating the XPath's that would result in identical XPath's from different implementations.

If it doesn't make the cut as something that goes into the DOM XPath interfaces, it should be used as a use case check.  That is, does the rest of DOM XPath enable generation of XPath's.

Received on Thursday, 19 July 2001 12:31:10 UTC