[jdom-interest] xpath [constructing path as you walk the tree ]

bob mcwhirter bob at werken.com
Thu May 30 10:24:58 PDT 2002


If you fully-qualify each step with a proximity predicate,
you can get the exact path with no problem.  The only issue
is that it's a fragile path, and any change to the document
could break it.

Paths the include semantic information are always more durable
than those containing mostly positional information.

ie:

	/a[1]/b[3]/c[5]

		versus

	/a/b/c[@cheese="gouda"]

-bob


On Thu, 30 May 2002, Laurent Bihanic wrote:

> Hi,
> 
> Dan Douglas wrote:
> > "Gu Xueying (Shinnie Gu)" <Shinnie.Gu at iuniverse.com.cn> writes:
> > 
> >>I want to get the path of each element when I walk through the jdom tree.
> > 
> > If you're already "walking" the tree, wouldn't it be easier and more
> > efficient to just construct the path as you move down the tree? 
> > 
> But this is actually quite difficult if Gu wants to get the exact XPath 
> selecting the current node as this may require an XPath expression with a test 
> subexpression.
> For example, in the following document:
> <a>
>   <b>
>    <c>1</c>
>    <d>2</d>
>    <c>3</c>
>    <d>4</d>
>   </b>
> </a>
> selecting the node <c>3</c> requires building an XPath expression like
>    /a/b/c[position() = '2']
> or
>    /a/b/*[position() = '3']
> 
> Given on document, building the XPath requires both walking the document tree 
> up to the root and the sibling list.
> If you code this, Gu, it would make a good helper class to add to jdom-contrib!
> 
> Laurent
> 
> _______________________________________________
> To control your jdom-interest membership:
> http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@yourhost.com
> 




More information about the jdom-interest mailing list