I’m stuck. I hope someone will take pity on a hack (programmed many years ago) who has been googling his fingers off, but still can’t find the answer to what I will think is a very simple answer.
I’m trying to separate the elements in this very simple xml file (temporarily published to the broader internet) : Wel Link
response data: date08/08/2015time08:43:42TotalBTU13994.269500
Content-Type : text/xml
Connection : close
Server : Z-World Rabbit
Date : Sat, 8 Aug 2015 08:43:14 GMT
Now, I could write code that could parse out the text response, but it would be ugly. I have read multiple places that httpGet returns a response that is an XMLSlurper object, but I can’t for the life of me figure out how to traverse/pull out the elements.
Anyone able to point me hopefully to one duh moment to get me over this seemingly simple issue?
Leaving up in case this helps someone in the future.
PS: It would still be nice to figure out how to access the elements by name, but I’m working on that next myself. I would think I could use the tree (.devices.device) instead of .children. Hmm.
[quote=“bridaus, post:2, topic:20253”]
It would still be nice to figure out how to access the elements by name
[/quote]If response.data has been parsed into an object, you can just treat it like an object. Based on your XML
response.data (or response.data.devices - not sure ) is an array, so
response.data[0].name
response.data[0].value
etc…
try log.debug response.data.inspect to get a dump of the response, it should be clear what’s in there.
Did you figure out how to access the value parameter?
I need some help in getting out the data I need from a solar inverter attached to my LAN that I can acces via xlm.
Below is my code:
def parse(String description) {
//this is automatically called when the hub action returns
log.debug "Got Reply"
def xml = parseLanMessage(description)
log.debug “body: ${xml.body}”
3a0fa8f1-a32c-4223-8bc9-8bd32ddea5a1 2:13:23 PM: debug Making xml request to C0A801DD:0050
3a0fa8f1-a32c-4223-8bc9-8bd32ddea5a1 2:13:23 PM: debug Uses which method: null
3a0fa8f1-a32c-4223-8bc9-8bd32ddea5a1 2:13:23 PM: debug The Header is [HOST:192.168.1.221:80]
3a0fa8f1-a32c-4223-8bc9-8bd32ddea5a1 2:13:23 PM: debug The device id configured is: C0A801DD:0050
3a0fa8f1-a32c-4223-8bc9-8bd32ddea5a1 2:13:23 PM: debug IP address entered is 192.168.1.221 and the converted hex code is c0a801dd
3a0fa8f1-a32c-4223-8bc9-8bd32ddea5a1 2:13:23 PM: trace Poll Called