Saturday, October 27, 2018

Double Slash ' // ' After Double Slash ' // ' In XPath

Double Slash ' // ' only selects all the nodes that are descendants of the matching nodes including the matching nodes themselves.

XPath having Double Slash ' // ' after Double Slash ' // ' is given below:
//div//span
For Example:

<div id='div_one'>
   <span id='span_one' />
   <div id='div_two'>
      <span id='span_two' />
   </div>
</div>
<div id='div_three'>
   <ul>
      <li>
         <span id='span_three' />
      </li>
   </ul>
</div>
<div id='div_four'>
   <p>
      <span id='span_four' />
   </p>
</div> 

Here, If we use '//div//span' XPath then we will get four 'span' nodes.

Why?
  • For '//div' we will get four div node (div_one, div_two, div_three & div_four) because Double Slash ' // ' selects all the nodes that are descendants of the matching nodes including the matching nodes themselves.
  • For '//span' we will get four span node (span_one, span_two, span_three & span_four) as span_one, span_two, span_three & span_four are the descendants of each of the div nodes (div_one, div_two, div_three & div_four) which were selected previously (by '//div').

No comments:

Post a Comment