Groovy web console

subscribe to the feed Subscribe
to this


Published 3 months ago by Anonymous with tags XmlSlurper
Actions Execute script  ▶ Edit in console Back to console Show/hide line numbers View recent scripts
String books = """
    <book available="20" id="1">
      <title>Don Quixote</title>
      <author id="1">Miguel de Cervantes</author>
    <book available="14" id="2">
      <title>Catcher in the Rye</title>
      <author id="2">JD Salinger</author>
    <book available="13" id="3">
      <title>Alice in Wonderland</title>
      <author id="3">Lewis Carroll</author>


def response = new XmlSlurper().parseText(books)

assert == 3
assert[-1].title.text() == 'Alice in Wonderland' // check last book title