tags:

views:

71

answers:

2

Example, if I have

<form name="blah">
   <input name="1"/>
   <input name="2"/>
   <table>
      <tr>
        <td>
          <unkown number of levels more>
           <input name="3"/>
        </td>
      </tr>
   <table>
</form>

How can I put together a query that will return input 1,2 and 3?

Edit: I should note I'm not interested in grabbing all the input elements on the page, I just want all the input elements that are children of a particular form, so "//" is right out.

+2  A: 

Use the double forward slash, so //input that will select all input elements, regardless of hierarchy.

If you just want all the input tags in the form element, use //form/input /form//input .

Edit: Yep, thanks for the correction Kragen.

Wim Hollebrandse
That will only return elements that are direct descendants of the form element, so in the above example 1 and 2, but not 3.
Kragen
+5  A: 

Use the // to search regardless of level. Keep in mind that this is an "expensive" search. So the more context you can specify, the faster XPath can call it up.

/html/path/to/form//input

is preferable. If you're in context of the form, even better. Your XPath query would look more like:

form//input

or if you just wanted children of the 'blah' form:

form[@name='blah']//input
Jweede
Ah excellent thank you.
gct