Get the second element of an XML file using Xpath

I have an XML-File and I want to get the second element the tree

<?xml version="1.0"?>
<catalog>
   <book id="bk101">
     <author>Gambardella, Matthew</author>
     <title>XML Developer's Guide</title>
   </book>
   <book id="bk102">
     <author>Freeman, Paul</author>
     <title>Getting well soon</title>
   </book>
</catalog>

I found this Xpath syntax for the first element

“string(/catalog/book/author/text()[1])”

so I thought I just change the 1 to a 2, but this does not work.
Does anyone know a solution?

@ClemensSteinbauer
give a try on
string(/catalog/book[1]/author/text())
and get returned: Gambardella, Matthew

string(/catalog/book[1]/title/text())
and get returned: XML Developer’s Guide

3 Likes

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.