How do you get the first entry into xpath?



  • How do you get the first entry into xpath without the daughters? The request for this type of "/div" will make all div out of the document.

    For example:

    <body>
       <div>1</div>
       <div>
         <span>2</span>
         <div>2.1</div>
       </div>
       <div>
         <div>3.1</div>
       </div>
       <span>
         <div>4</div>
       </span>
    </body>
    

    The result of the operation would be to see not all div, but only four records:

    1
    <span>2</span>
    <div>2.1</div>
    <div>3.1</div>
    4
    


  • That's the way you're gonna work.

    (//div)[1]
    


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2