How to retrieve a node using xpath in java

Hi,I need to make an application in which on click of a button an xml isdisplayed on the browser.Now when a user selects a node in the xml then i need the xpath of the selected node for some processing.How to retrieve the xpath.I am using Struts
[298 byte] By [Anand.Aa] at [2007-11-27 4:32:08]
# 1
There is not a specific method for achieving this. You can store the whole xml document into a defined structure. And get the needed xpath by some index.
youhaodiyia at 2007-7-12 9:41:41 > top of Java-index,Java Essentials,Java Programming...
# 2

> There is not a specific method for achieving this.

> You can store the whole xml document into a defined

> structure. And get the needed xpath by some index.

Yes i know that i'll need to store the file.

But my XML is fixed and the same XML is used everytime.

Now the structure of the XML is like it has same named nodes inside the parent node.

example :

<Human>

<Person>

<Person></Person>

<Person>

<Person><name>fsfsdsdf</name></Person>

</Person>

</Person>

<Human>

Now if the user selects the person node which contains name node then how to get the XPATH.

Can u help regarding the same........

Anand.Aa at 2007-7-12 9:41:41 > top of Java-index,Java Essentials,Java Programming...
# 3

I imagine that you could backtrack up the DOM tree to the root, appending the element name to the xpath, but my question is why? Xml isn't designed to be used this way. If you want to load that data into a tree structure for the user to make selection from, then do that. But don't use the xml dom tree, use the tree structure that you loaded to xml data into. The tree should have a Person object in that location, that the user can select. That Person selection should know everything about itself that you need to know. If you still need to know where in the tree the selection is, then just follow the parents up to the root.

hunter9000a at 2007-7-12 9:41:41 > top of Java-index,Java Essentials,Java Programming...
# 4

Thanx Man.

I know that XML is not to be used in this way but somehow its the

constraint of the application that i have to implement the same.

Its like that on click of a button a static xml is shown and user must be able to see the xml so as to see the values and everything associated to the xml nodes.

Now when the user selects the particular node then i need to track the xpath of the selected node and hence also store the value associated with the node which in turn is a necessity to implement.

I have tried to do same with a handy javascript but its not very relaible

moreover i want to do thru java to make the logic robust

HELP ME...!!!!!

Anand.Aa at 2007-7-12 9:41:41 > top of Java-index,Java Essentials,Java Programming...