Retrieve and parse xml data

Alright, so the response from the server is getting parsed into a GPathResult automatically. You can read up about it here: The Apache Groovy programming language - Processing XML

result.data is your "apps" node of the xml and you can get its first child like this:
response.data.app[0]

and get the data in the node like this:
response.data.app[0].text()
or any attribute on the node with the @ symbol like this:
response.data.app[0].@version

Here is your chunk of code modified so it will print out the name and version of each Node in "apps":

    def params = [
        uri: "http://192.168.7.243:8060/query/apps",	
        contentType: "text/xml"
    ]
    try {
        httpGet(params){response ->
            if(response.status != 200) {
                log.error "error: ${response.status}."
            } else {
                log.debug "Connected to Roku Successfully"
                response.data.app.each { app ->
                    log.debug "name: ${app.text()} version: ${app.@version}"
        		}
				log.info response.contentType
            }
        }
    } catch (e){
        log.error "error:${e.getResponse().getData()}"
    } 
4 Likes