Why // is required instead of /

consider the following HTML code:

<html>
<head>      
  <title>Example website</title>
</head>
 <body>    
  <div>
  <table id='tableid'>
   <tr>
    <td>
        <a href="/blabla" title="Blabla1">Blabla1</a>
        <a href="/blabla" title="Blabla1">Blabla2</a>
        <a href="/blabla" title="Blabla1">Blabla3</a>
        <a href="/blabla" title="Blabla1">Blabla4</a>
    </td>
        <td>col2</td>
        <td>col3</td>
        <td>col4</td>
   </tr>
  </table>
 </body>
</html>

If I want to get all the links, why should I use:

//table[@id="tableid"]//a/@href

instead, if you use one / after the table? I am alredy on the node table at this moment (it should become my "root"), so / should be enough ...

early!

+4
source share
2 answers

One /after table[@id="tableid"]will work if you need only direct children from table. To get any child aout table[@id="tableid"]you need //a.

// not suitable for /descendant-or-self::node()/

node node. node table[@id="tableid"], a , , table[@id="tableid"].

+4
//table[@id="tableid"]

<table> id tableid.

//a/@href

<a> <table>, (, ...)

, <a>, , <td> (table → tr → td), // :

//table[@id="tableid"]/tr[1]/td[1]/a/@href

/tr[1]/td[1] <a>.

+3

All Articles