String books = """ <response> <books> <book available="20" id="1"> <title>Don Quixote</title> <author id="1">Miguel de Cervantes</author> </book> <book available="14" id="2"> <title>Catcher in the Rye</title> <author id="2">JD Salinger</author> </book> <book available="13" id="3"> <title>Alice in Wonderland</title> <author id="3">Lewis Carroll</author> </book> </books> </response> """ def response = new XmlSlurper().parseText(books) assert response.books.book.size() == 3 assert response.books.book[-1].title.text() == 'Alice in Wonderland' // check last book title