Help extracting an array of elements

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.

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).

and here is the java in Tasker that parses it

Wait, is this Java or JavaScript?

Sorry - took me a bit to find this thread - it dropped off the Javascript forum list.

It’s javascript. Tasker is a pseudo programming language for android phones. It lets you run 'javascriptlet’s within it

paul

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.