Parsing XML Data for Device


#1

I have been trying to work out device code that can read values from an XML file published by a device on my network. Looked over the XML guide that has been referenced by others and various topics about parsing, plus tried using some http code people have posted. But I never seem to get a useful value, always Null. So I know I am missing something, probably something simple... So I felt I should ask for recommendations or samples I should try. I CAN successfully determine if the device is "Online" (presence detection) but reading values, no luck.

Here is a sample of the XML:

<probes>
<probe>
<name>Tmp</name>
<value>77.6</value>
<type>Temp</type>
</probe>

I do not even REALLY need to treat this as XML. If I could parse the value out (like I do on my phone with Tasker) that would work as well. Since the probe name will always be a specific one I am looking for followed by the value. In all the cases I am looking at the value would be a number. The type field does not matter but I wanted to give a complete "probe" sample at least.

Does anyone have any samples or recommendations I should look over or try? I can post Code samples later if anyone needs, but I have tried many things so anything I post would only be representative of the "current attempt" and not all the previous failures.


#2

Not knowing your comms detail, I use in my code the following code (modified for you). There may be some structural differences

def parse(resp) {
def respData = new XmlSlurper().parseText(resp.body)
def name = probes.probe.name
def value = probes.probe.value
def type = probes.probe.type
}

dave