Get XPath of an element tag

Discussion in 'Java' started by anupamjain@gmail.com, Mar 3, 2006.

  1. Guest

    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
     
    , Mar 3, 2006
    #1
    1. Advertising

  2. <> wrote in message
    news:...
    >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.
    >


    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
     
    Mike Schilling, Mar 3, 2006
    #2
    1. Advertising

  3. Guest

    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.
     
    , Mar 3, 2006
    #3
  4. <> wrote in message
    news:...
    > 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]
     
    Mike Schilling, Mar 3, 2006
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Marvin_123456

    "Memory leak" in javax.xml.xpath.XPath

    Marvin_123456, Jul 29, 2005, in forum: Java
    Replies:
    4
    Views:
    2,008
    jan V
    Jul 29, 2005
  2. shruds
    Replies:
    1
    Views:
    893
    John C. Bollinger
    Jan 27, 2006
  3. Ian Wilson
    Replies:
    2
    Views:
    568
    Ian Wilson
    Jul 26, 2007
  4. Kniffel
    Replies:
    8
    Views:
    2,022
    Kniffel
    Sep 7, 2007
  5. HANM
    Replies:
    2
    Views:
    750
    Joseph Kesselman
    Jan 29, 2008
Loading...

Share This Page