Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / March 2006

Tip: Looking for answers? Try searching our database.

Get XPath of an element tag

Thread view: 
anupamjain@gmail.com - 03 Mar 2006 04:27 GMT
I am trying to 'grab' the XPath of an element as soon as the user
clicks on it. So I am putting a span tag around that element (it's
actually a <td>) and onmouseover it gets highlighted, now I want that
onmouseclick, I grab the XPath of that td tag. Is there a built in
method to do this in Xpath API (for eg. can I pass the span 'id' to a
function and get the Xpath?)

It's a JSP page where I will be importing the Java file where I will be
using the XPath API.

Also, if there's a better way to do all that I am doing, please let me
know.

Thanks,
Anupam
Mike Schilling - 03 Mar 2006 05:19 GMT
>I am trying to 'grab' the XPath of an element as soon as the user
> clicks on it. So I am putting a span tag around that element (it's
[quoted text clipped - 5 lines]
> It's a JSP page where I will be importing the Java file where I will be
> using the XPath API.

If I'm understanding you and the result is something like

   <span id="uniqueID">
       <td/>
   </span>

you can use the expression

   //span[@id="uniqueID"]/td
anupamjain@gmail.com - 03 Mar 2006 05:36 GMT
Yeah, but the span tag is 'dynamically' used to highlight the cell. So
if the user comes to that page again, he wont see the span tag at
all.(because I add the span tags before displaying it to the user). So
i want to grab the entire Xpath without using span in between, so if
the user comes that page again, i can retrieve the Xpath (from a
database for e.g) and trace back to that tag.
Mike Schilling - 03 Mar 2006 17:24 GMT
> Yeah, but the span tag is 'dynamically' used to highlight the cell. So
> if the user comes to that page again, he wont see the span tag at
> all.(because I add the span tags before displaying it to the user). So
> i want to grab the entire Xpath without using span in between, so if
> the user comes that page again, i can retrieve the Xpath (from a
> database for e.g) and trace back to that tag.

Oh.  In that case, it's harder.  You need to navigate via parent nodes to
the document element, at each node figuring out how many previous sibling
nodes there are with the same name, and generate an XPath like

   /level1/level2[2]/level3[1]/level4[1]/td[12]


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.