tags:

views:

18

answers:

1

trying to get my head around a problem, not sure if there really is a solution, or a solution that's readily available. i'm trying to figure out if i can specify a "term" that's in the source of a webpage, and have the "blackbox" produce a fully qualified XPath for the DOM element that contains/has/uses the "term"

in other words, if i have a page, that has <a href="bbb" name='foo'>, i'd like to be able to specify something like:

attribute="name
data="foo"

and the output would be the fully qualified XPath to get the <a/> item

i'm looking for a the beginnings of a tool that would allow me to specify the specific elements of a webpage; the app/function would parse the DOM/page, build the tree, and then return the fully qualified XPath for the inputs..

i've looked/searched through various data on the net, with not much success...

UPDATE:: I'm not looking for a solution to create a single XPath, I'm looking for how to generalize this issue...

i can easily create an XPath for a given scenario... but i want to go the other way.

i want the "blackbox" to give me the "//...[@name="foo"]

so based on the inputs, the app would determine if the page has the element, and then generate the correct XPath for the DOM element...

in this manner, i might specify a form, and anchor, a whatever, and as long as i define the elementtype/id/name, the output would be the qualified XPath to then generate the data for the item/element.

hope that clarifies things a bit..

A: 

Try out XPather

In your query you specify something like: //*[@name="foo"], then you copy the full Xpath from the results window.

spektom
hey spektom...you miss my issue/question.. i can easily create an XPath for a given scenario... but i want to go the other way. i want the "blackbox" to give me the "//...[@name="foo"] so based on the inputs, the app would determine if the page has the element, and then generate the correct XPath for the DOM element...
tom smith
The `//*[@name="foo"]` is an input query to the blackbox (called XPather), which means: find all elements that have an attribute `name` with value `foo` (this is since XPather only understand XPath input format). The blackbox finds all the elements that match this query (there can be more than one element), then you ask from the blackbox to generate full Xpaths for every element it has found. I'm pretty sure you can reuse XPather programmatically as well.
spektom
hey spektom...thanks again.. but again, i don't want to craft any xpath to feed to a black box for it to return the data.i want to feed an "element type", and an attribute, and have the black box return the XPath, which could then be used to return/generate the final resulting dataset...xpather doesn't accomplish this. xpather requires an xpath function/query to then parse the dom...thanks
tom smith