I am an xml dummy. I’m writing some stuff for tasker to grab information from a home alarm system so that I can display it on my phone using Tasker.
This is a snippet of xml that gets returned to a call from which I can retrieve some information about a variable
<var type="1" id="1">
<init>2</init>>
<prec>0</prec>>
<val>2</val>>
<ts>20210402 19:49:31</ts>
</var>
and here is the java in Tasker that parses it
parser = new DOMParser();
var xmlDoc = parser.parseFromString(global('HTTPD'),"text/xml");
var varHeader = xmlDoc.getElementsByTagName("var")[0];
setGlobal("varLastType",varHeader.getAttribute("type")); setGlobal("varLastID",varHeader.getAttribute("id")); setGlobal("varLastSet",xmlDoc.getElementsByTagName("ts")[0].childNodes[0].nodeValue); setGlobal("varLastVal",xmlDoc.getElementsByTagName("val")[0].childNodes[0].nodeValue); setGlobal("varLastInit",xmlDoc.getElementsByTagName("init")[0].childNodes[0].nodeValue);
after it runs I have global variables in Tasker - varLastVal, varLastInit, etc.
I more or less understand that.
Now I have another chunk of xml that I’d like to parse but don’t know how.
<status>
<ae type="1" area="1" val="0"/>
<ae type="3" area="1" val="0"/>
<ae type="2" area="1" val="1"/>
<ae type="1" area="2" val="0"/>
<ae type="2" area="5" val="4"/>
<ze type="51" zone="1" val="0"/>
<ze type="52" zone="1" val="3"/>
<ze type="53" zone="1" uom="dV" val="0"/>
<ze type="56" zone="1" val="-60"/>
<ze type="51" zone="2" val="0"/>
<ze type="52" zone="2" val="3"/>
<ze type="53" zone="2" uom="dV" val="0"/>
<ze type="56" zone="2" val="-60"/>
</status>
I’d like to do the same thing that the first code does - set up global variables - but in an array of them - so that when it was done I would have an array of aetype[n], aearea[n] and aeval[n], and the same for zetype, zezone, zeuom and zeval.