[jdom-interest] xpath [constructing path as you walk the tree
]
Laurent Bihanic
laurent.bihanic at atosorigin.com
Thu May 30 09:50:38 PDT 2002
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
More information about the jdom-interest
mailing list