Created
February 22, 2018 08:32
-
-
Save amitbhadra/af413251f12ca23522b8ad19021f8535 to your computer and use it in GitHub Desktop.
Parse a XML string in groovy using XmlSlurper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
books = ''' | |
<response version-api="2.0"> | |
<value> | |
<books> | |
<book available="20" id="1"> | |
<title>Don Xijote</title> | |
<author id="1">Manuel 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> | |
<book available="5" id="4"> | |
<title>Don Xijote</title> | |
<author id="4">Manuel De Cervantes</author> | |
</book> | |
</books> | |
</value> | |
</response> | |
''' | |
response = new XmlSlurper().parseText(books) | |
response.value.books.book.each{ | |
bookname = it.title | |
println bookname | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment