HomeGenie Forum

Automation Program Plugins and Wizard Scripting => Help => Topic started by: codedmind on April 23, 2015, 10:46:11 PM

Title: Help with xml response
Post by: codedmind on April 23, 2015, 10:46:11 PM
I there, i have the following xml
Code: [Select]
<response>
<device id="22114" type="1" period="5"/>
<data time="1429815600" status="43" current="1366">
<energy>22929984</energy>
<power>314</power>
</data>
</response>
and the following code
Code: [Select]
dynamic test = Net.WebService(url).GetData();

Program.Notify("Test", test.Replace("<","&lt").ToString());
Pause(15);
Program.Notify("Test", test.response.ToString());

The first notify show me the xml (the replace is the only way i can find to see the output) in the second notify however i get an error,    string does not contain a definition for `response'

Any help?

Other question is how can i get the attribute value? (for example device id value)?
Title: Re: Help with xml response
Post by: nolio on April 24, 2015, 09:13:17 AM
You can use this method : http://www.homegenie.it/docs/doxy/a00006.html#a08d047072bdd8bcefd1645de3dc6eda0 (http://www.homegenie.it/docs/doxy/a00006.html#a08d047072bdd8bcefd1645de3dc6eda0)

in the example :
Code: [Select]
var iplocation = Net.WebService("http://freegeoip.net/json/").GetData();
Program.Notify("IP to Location", iplocation.city);

iplocation.city => city is the name of "XML" Tag.
You can try by calling : http://freegeoip.net/json/ (http://freegeoip.net/json/) and search city

So in your example : test.energy should return 22929984
Title: Re: Help with xml response
Post by: codedmind on April 24, 2015, 09:56:26 PM
thanks for your reply.

I already try it, that is json, and i use xml... don't know why... but i still have a crc error
`string' does not contain a definition for `energy'
Title: Re: Help with xml response
Post by: nolio on April 24, 2015, 10:45:04 PM
Ok, i think i already do it with XML, but probably a mistake ..
So i don't have any advise on my side. Sorry.