Question

I'm very a newbie with xpath started looking at it today :)

I have some html that have the following structure :

<body class="wrapper">
   <h3>someText_1</h3>
   <h4>someOtherText_1
      <a href="someLink_1"> link_1 </a>
   </h4>
   <p>description_1</p>
          ...     
   <h3>someText_n</h3>
   <h4>someOtherText_n
      <a href="someLink_n"> link_1 </a>
   </h4>
   <p>description_1</p>
</body>

Is it possible using xpath to select all the nodes after each h3? or more generally : given a node is it possible to select the followings n-nodes if these are not children of the given node?

I have tried with :

  1. //body[class="wrapper]/h3/*
  2. //body[class="wrapper]/h3/.
Was it helpful?

Solution

What you are looking for is following-sibling::*

All notes after hr:

//body[@class="wrapper"]/h3/following-sibling::*

The next one only

//body[@class="wrapper"]/h3/following-sibling::*[1]

The next three:

//body[@class="wrapper"]/h3/following-sibling::*)[position() <= 3 ]'

For more information have a look to xpah axes

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top