Facility Control

 View Only
Expand all | Collapse all

XML parsing

João victhor Mariano

João victhor Mariano04-20-2020 18:50

  • 1.  XML parsing

    Posted 04-17-2020 13:10

    Hello,

    In the last days, I've been watched videos from dashboardU, but one's of them made me curious, especially, because I have many doubts about it. The lesson 107, about XML parsing, is the responsible for it.

    I tried to copy the code and steps, showed during the video, and did my own custom panel, but it isn't working fine. Even I creating the XML file, and putting them inside a same folder where my panel is, seems that the parameters is not recognized, because when I press the 'XPath button', nothing happens on the panel.

    In a nutshell, I'm simulating a tv schedule grid, where is possible to see different types of channels, and check which film will be exhibit and what's time it wiil be happen.

    NOTE: I'm simulating on offline mode of Dashboard (There is no equipment connect to my pc)

    Could you help me identify what is going wrong, please?

    Follow Link. 

    http://www.mediafire.com/folder/3pfnajp4tdnqh/XML1 



  • 2.  RE: XML parsing

    Posted 04-20-2020 13:28

    what does the debug messages say? when i did this i had problems with the file path, bc the example uses a key lookup with a constant filename, which i found a bit confusing, so i basically bypassed all this and just copied my file path into the button task, like this:

    var filepath = ogscript.parseXML('file:///C:/folderName/myXMLfile.xml');


    #DashBoard


  • 3.  RE: XML parsing

    Posted 04-20-2020 13:51

    Hello, 

     

    Thanks for your help.

    So, doesn't have a specific error's message. I think you could realize that when you open the archive of PanelBuilder, it's seems everything is nice, but when XPath button is pressed all information inside of tables bacomes ''Blanks or 0'', right?  

    Thus, when other buttons are pressed, and theorically all information would have to return to normal, it's doesn't happen. What I could understand about your answer was I must copy my file path into the button task and the problem will be solved. 

    Did you try to do it with my archive that I shared through the link above? Was it work? 

     


    #DashBoard


  • 4.  RE: XML parsing

    Posted 04-20-2020 14:19

    i can't travel to that link at work, but if you copy the code from the xpath button and paste it here i will check it out.


    #DashBoard


  • 5.  RE: XML parsing

    Posted 04-20-2020 14:26

    Ok, I'll do that.

    Follow code lines:

    var filepath = ogscript.getPrivateString('constants','filepath');
    var XMLDoc;
    ogscript.debug('Reading XML file: ' + filepath);
    XMLDoc = ogscript.parseXML(file:/C:/Users/joaoa/OneDrive/Desktop/XML1/XMLExample1.xml);
    if (XMLDoc == null) {
    ogscript.debug('Failed to read file');
    } else {
    ogscript.debug('Parsing XML');
    var found = ogscript.runXPath('/Channel/canal', XMLDoc);
    ogscript.debug('search found ' + found.length + ' items');
    params.setValue(0xb, 0, found.length); // canais = length
    for (var i = 0; i < found.length; i++) {
    var node = found.item(i);
    var canalname = node.getAttribute('name');
    var filename = node.getAttribute('filename');
    ogscript.debug(i + ": " + canalname + ", " + filename);
    params.setValue(7, i, canalname); // canalNames[i] = canalname
    params.setValue(8, i, filename); // canalFilePaths[i] = filename
    }
    params.setValue(0x9, 0, 0); // Channel = 0 (triggers on change)

    }

     

    Thanks,


    #DashBoard


  • 6.  RE: XML parsing

    Posted 04-20-2020 15:19

    try to comment out the first 3 lines and then put the file path argument in single quotes, like this:

    //var filepath = ogscript.getPrivateString('constants','filepath');
    //var XMLDoc;
    //ogscript.debug('Reading XML file: ' + filepath);
    XMLDoc = ogscript.parseXML('file:/C:/Users/joaoa/OneDrive/Desktop/XML1/XMLExample1.xml');


    #DashBoard


  • 7.  RE: XML parsing

    Posted 04-20-2020 15:27

    Ok,

    I applied this to three buttons, but error persists. Should I replicate these changes in the general code as well? 


    #DashBoard


  • 8.  RE: XML parsing

    Posted 04-20-2020 15:29

    actually, i just realized the way i was doing my project won't work for you, so go back to the way you had it. i'll check this out when i get home later. sorry. i kind of sent you in a wrong direction, but i'll check it out when i get home this evening.

    so change your code back to this:

    var filepath = ogscript.getPrivateString('constants','filepath');
    var XMLDoc;
    ogscript.debug('Reading XML file: ' + filepath);
    if (XMLDoc == null) {
    ogscript.debug('Failed to read file');
    } else {
    ogscript.debug('Parsing XML');
    var found = ogscript.runXPath('/Channel/canal', XMLDoc);
    ogscript.debug('search found ' + found.length + ' items');
    params.setValue(0xb, 0, found.length); // canais = length
    for (var i = 0; i < found.length; i++) {
    var node = found.item(i);
    var canalname = node.getAttribute('name');
    var filename = node.getAttribute('filename');
    ogscript.debug(i + ": " + canalname + ", " + filename);
    params.setValue(7, i, canalname); // canalNames[i] = canalname
    params.setValue(8, i, filename); // canalFilePaths[i] = filename
    }
    params.setValue(0x9, 0, 0); // Channel = 0 (triggers on change)

    }


    #DashBoard


  • 9.  RE: XML parsing

    Posted 04-20-2020 15:34

    correction:

    var filepath = ogscript.getPrivateString('constants','filepath');
    var XMLDoc;
    ogscript.debug('Reading XML file: ' + filepath);
    XMLDoc = ogscript.parseXML(filepath);
    if (XMLDoc == null) {
    ogscript.debug('Failed to read file');
    } else {
    ogscript.debug('Parsing XML');
    var found = ogscript.runXPath('/Channel/canal', XMLDoc);
    ogscript.debug('search found ' + found.length + ' items');
    params.setValue(0xb, 0, found.length); // canais = length
    for (var i = 0; i < found.length; i++) {
    var node = found.item(i);
    var canalname = node.getAttribute('name');
    var filename = node.getAttribute('filename');
    ogscript.debug(i + ": " + canalname + ", " + filename);
    params.setValue(7, i, canalname); // canalNames[i] = canalname
    params.setValue(8, i, filename); // canalFilePaths[i] = filename
    }
    params.setValue(0x9, 0, 0); // Channel = 0 (triggers on change)

    }


    #DashBoard


  • 10.  RE: XML parsing

    Posted 04-20-2020 15:37

    or you can paste all the code here. i know it's quite a few files to do that for, but that's the only way i can look at it until i get home.


    #DashBoard


  • 11.  RE: XML parsing

    Posted 04-20-2020 16:06

    Don't worry, you're being very king for helping me.

    So, I'll post the general code here:

    <abs contexttype="opengear" id="_top" keepalive="false">
    <meta>
    <params>
    <param access="1" constrainttype="INT_CHOICE" name="ChannelTable" oid="0x9" precision="0" type="INT16" value="0" widget="default">
    <constraint key="7">Canal</constraint>
    <constraint key="8">Datafile</constraint>
    </param>
    <param access="1" maxlength="0" name="ChannelCineName" oid="0x2" precision="0" type="STRING_ARRAY" widget="default">
    <value>blank</value>
    <value>blank</value>
    <value>blank</value>
    <value>blank</value>
    </param>
    <param access="1" constrainttype="INT_NULL" name="ChannelTime" oid="0x5" precision="0" type="INT16_ARRAY" value="0;0;0;0" widget="default"/>
    <param access="1" maxlength="0" name="ChannelFilme" oid="0x6" precision="0" type="STRING_ARRAY" widget="default">
    <value>blank</value>
    <value>blank</value>
    <value>blank</value>
    <value>blank</value>
    </param>
    <param access="1" constrainttype="INT_NULL" name="ChannelNumero" oid="0x3" precision="0" type="INT16_ARRAY" value="0;0;0;0" widget="default"/>
    <param access="1" constrainttype="INT_CHOICE" name="Squad" oid="0x4" precision="0" type="INT16" value="3" widget="table">
    <constraint key="3">Numero</constraint>
    <constraint key="2">Canal</constraint>
    <constraint key="6">Filme</constraint>
    <constraint key="5">Horario</constraint>
    </param>
    <param access="1" constraint="0.0;100.0;0.0;100.0;1" constrainttype="INT_STEP_RANGE" name="squadSize" oid="0xA" precision="0" type="INT16" value="0" widget="default"/>
    <param access="1" maxlength="0" name="canalFilePaths" oid="0x8" precision="0" type="STRING_ARRAY" widget="default">
    <value>blank</value>
    <value>blank</value>
    <value>blank</value>
    </param>
    <param access="1" maxlength="0" name="canalNames" oid="0x7" precision="0" type="STRING_ARRAY" widget="default">
    <value>blank</value>
    <value>blank</value>
    <value>blank</value>
    </param>
    <param access="1" constraint="0.0;20.0;0.0;20.0;1" constrainttype="INT_STEP_RANGE" name="canal" oid="0xB" precision="0" type="INT16" value="0" widget="default"/>
    <param access="1" maxlength="0" name="UNCChannelNameFirst" oid="0x101" precision="0" type="STRING_ARRAY" widget="default">
    <value>blank</value>
    </param>
    <param access="1" constrainttype="INT_NULL" name="UNCChannelNumber" oid="0x100" precision="0" type="INT16_ARRAY" value="0" widget="default"/>
    </params>
    </meta>
    <drawer height="263" left="38" style="bg-u:file:/C:/Users/joaoa/OneDrive/Pictures/dashboard/telecine.jpg;bg-align:center;bdr:round;" tabfill="none" top="159" width="420"/>
    <split height="481" left="522" orientation="horizontal" top="118" width="837">
    <abs weight="0.5">
    <param expand="true" height="238" left="79" oid="0x9" scroll="true" showlabel="false" top="89" widget="table" width="322">
    <task tasktype="ogscript">var filepath = params.getValue(8,params.getValue(9,0));
    ogscript.debug ("Canal datafile: " + filepath);
    ogscript.rename ('squadLabel', params.getValue(7, params.getValue(9,0)));
    var XMLDoc = ogscript.parseXML(filepath);
    if (XMLDoc == null) {
    ogscript.debug('Failed to read team data file');
    } else {
    // clear out the existing squad data
    for (var i = 0; i &lt; params.getValue(0xa, 0); ++i) {
    params.setValue(2, i, "blank");
    params.setValue(3, i, 0);
    params.setValue(5, i, 0);
    params.setValue(6, i, "blank");
    }
    ogscript.debug('Parsing XML');
    var found=XMLDoc.getElementsByTagName('channel');
    ogscript.debug('search found ' + found.length + ' items');
    params.setValue(0xa, 0, found.length);
    for (var i = 0; i &lt; found.length; i++) {
    var node = found.item(i);
    var numero = node.getAttribute('numero');
    var cinename = node.getAttribute('cinename');
    var filme = node.getAttribute('filme');
    var time = node.getAttribute('time');
    ogscript.debug(i + ": " + numero + ", " + cinename + ", " + filme + ", " + time);
    params.setValue(3, i, Number(numero));
    params.setValue(2, i, cinename);
    params.setValue(5, i, time);
    params.setValue(6, i, filme);
    }
    }</task>
    </param>
    </abs>
    <abs style="txt-align:center;">
    <param anchor="west" bottom="383" expand="true" fill="both" id="table" left="0" name="Programação" oid="0x4" right="111" scroll="true" showlabel="false" top="0" weightx="1.0" weighty="1.0">
    <task tasktype="ogscript"/>
    </param>
    <table height="120" left="21" style="bdr:etched;" top="316" width="389">
    <tr>
    <button buttontype="push" colspan="1" fill="both" height="120" left="443" name="XPath" rowspan="1" top="85" weightx="1.0" weighty="1.0" width="136">
    <task tasktype="ogscript">var filepath = ogscript.getPrivateString('constants','filepath');
    var XMLDoc;
    ogscript.debug('Reading XML file: ' + filepath);
    XMLDoc = ogscript.parseXML(filepath);
    if (XMLDoc == null) {
    ogscript.debug('Failed to read file');
    } else {
    ogscript.debug('Parsing XML');
    var found = ogscript.runXPath('/Channel/canal', XMLDoc);
    ogscript.debug('search found ' + found.length + ' items');
    params.setValue(0xb, 0, found.length); // canais = length
    for (var i = 0; i &lt; found.length; i++) {
    var node = found.item(i);
    var canalname = node.getAttribute('name');
    var filename = node.getAttribute('filename');
    ogscript.debug(i + ": " + canalname + ", " + filename);
    params.setValue(7, i, canalname); // canalNames[i] = canalname
    params.setValue(8, i, filename); // canalFilePaths[i] = filename
    }
    params.setValue(0x9, 0, 0); // Channel = 0 (triggers on change)

    }</task>
    </button>
    <button buttontype="push" colspan="1" fill="both" height="120" left="443" name="Tag Gets" rowspan="1" top="85" weightx="1.0" weighty="1.0" width="136">
    <task tasktype="ogscript">var filepath = ogscript.getPrivateString('constants','filepath');
    var XMLDoc;
    ogscript.debug('Reading XML file: ' + filepath);
    XMLDoc = ogscript.parseXML(filepath);
    if (XMLDoc == null) {
    ogscript.debug('Failed to read file');
    } else {
    ogscript.debug('Parsing XML');
    var found=XMLDoc.getElementsByTagName('canal');
    ogscript.debug('search found ' + found.length + ' items');
    params.setValue(0xb, 0, found.length); // canais = length
    for (var i = 0; i &lt; found.length; i++) {
    var node = found.item(i);
    var canalname = node.getAttribute('name');
    var filename = node.getAttribute('filename');
    ogscript.debug(i + ": " + canalname + ", " + filename);
    params.setValue(7, i, canalname); // canaisNames[i] = canaisname
    params.setValue(8, i, filenema); // canalFilePaths[i] = filecanais
    }
    params.setValue(0x9, 0, 0); // ChannelTable = 0 (triggers onchange)

    }</task>
    </button>
    <button buttontype="push" colspan="1" fill="both" height="120" left="0" name="Init" top="0" weightx="1.0" weighty="1.0" width="136">
    <task tasktype="ogscript">var squadSize = params.getValue(0xa, 0);
    var canal = params.getValue(0xb, 0);

    for (var i = 0; i &lt; squadSize; i++)
    {
    params.setValue(0x2, i, "blank");
    params.setValue(0x3, i, 0);
    params.setValue(0x5, i, "0");
    params.setValue(0x6, i, "blank");
    }
    for (var i = 0; i &lt; canal; ++i)
    {
    params.setValue(0x7, i, "blank");
    params.setValue(0x8, i, "blank");
    }
    params.setValue(0xa, 0, 0);
    params.setValue(0xb, 0, 0);
    ogscript.rename('squadLabel', 'blank');</task>
    </button>
    </tr>
    </table>
    </abs>
    </split>
    </abs>


    #DashBoard


  • 12.  RE: XML parsing

    Posted 04-20-2020 17:37

    can u paste those xml files too?


    #DashBoard


  • 13.  RE: XML parsing

    Posted 04-20-2020 17:45

    Yes,sure.

    XML 'canal':

    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <canal name="Telecine">
    <squad>
    <Channel numero="653" canal="Telecine Pipoca" name="Shaw & Robs" horario="10"/>
    <Channel numero="654" canal="Telecine Action" name="Jhon Wick" horario="14"/>
    </squad>
    </canal>

     

    XML 'Channel':

    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <Channel name="EPL">
    <canal name="Telecine" filename="Telecine.xml"/>
    <canal name="HBO" filename="HBO.xml"/>
    <canal name="Sportv" filename="Sportv.xml"/>
    </Channel>

     

    XML'HBO':

    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <canal name="HBO">
    <squad>
    <Channel numero="753" canal="HBO1" name="Dr. Estranho" horario="9"/>
    <Channel numero="754" canal="HBO2" name="Preto ou Branco" horario="11"/>
    <Channel numero="755" canal="HBO PLUS" name="Eu e as Mulheres" horario="21"/>
    <Channel numero="756" canal="HBO Family" name="Homem Aranha" horario="23"/>

    </squad>
    </canal>

     

    XML 'Sportv' : 

    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <canal name="Sportv">
    <squad>
    <Channel numero="553" canal="Sportv1" name="Sportv News" horario="8"/>
    <Channel numero="554" canal="Sportv2" name="Redação Sportv" horario="13"/>

    </squad>
    </canal>

     

    XML 'Telecine' :

    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <canal name="Telecine">
    <squad>
    <Channel numero="653" canal="Telecine Pipoca" name="Shaw & Robs" horario="10"/>
    <Channel numero="654" canal="Telecine Action" name="Jhon Wick" horario="14"/>
    <Channel numero="655" canal="Telecine Premium" name="007 Skyfall" horario="16"/>
    <Channel numero="656" canal="Telecine Cult" name="Titanic" horario="18"/>

    </squad>
    </canal>

     

    XML 'XMLExample1' : 

     

    <?xml version="1.1" encoding="UTF-8"?>
    <card autosave="true" online="true" slot="1"

    sourceframe="file-collection-frame&lt;br>1392749521282"
    sourceframename="Frame"
    sourceid="file:/C:/Users/joaoa/OneDrive/Desktop/XML1/XMLExample1.xml"
    status="2" statustext="OK" version="2.0">
    <params>
    <param access="1" maxlength="0" name="ChannelCineName" oid="0x2"
    precision="0" type="STRING_ARRAY" widget="default">
    <value>Telecine Pipoca</value>
    <value>Telecine Action</value>
    <value>Telecine Premium</value>
    <value>Telecine Cult</value>
    </param>
    <param access="1" constrainttype="INT_NULL" name="ChannelNumero"
    oid="0x3" precision="0" type="INT16_ARRAY"
    value="653;654;655;656" widget="default">
    <strvalue>653</strvalue>
    <strvalue>654</strvalue>
    <strvalue>655</strvalue>
    <strvalue>656</strvalue>
    </param>
    <param access="1" constrainttype="INT_CHOICE" name="Squad"
    oid="0x4" precision="0" strvalue="0" type="INT16"
    value="0" widget="table">
    <constraint key="3">Numero</constraint>
    <constraint key="2">Canal</constraint>
    <constraint key="6">Filme</constraint>
    <constraint key="5">Horario</constraint>
    </param>
    <param access="1" maxlength="0" name="ChannelTime"
    oid="0x5" precision="0" type="INT16_ARRAY" widget="default">
    <value>10</value>
    <value>14</value>
    <value>16</value>
    <value>18</value>
    </param>
    <param access="1" maxlength="0" name="ChannelFilme"
    oid="0x6" precision="0" type="STRING_ARRAY" widget="default">
    <value>Shaw & Robs</value>
    <value>Jhon Wick</value>
    <value>007 Skyfall</value>
    <value>Titanic</value>
    </param>
    <param access="1" maxlength="0" name="canalNames" oid="0x7"
    precision="0" type="STRING_ARRAY" widget="default">
    <value>Telecine</value>
    <value>HBO</value>
    <value>Sportv</value>
    </param>
    <param access="1" maxlength="0" name="canalFilePaths" oid="0x8"
    precision="0" type="STRING_ARRAY" widget="default">
    <value>Telecine.xml</value>
    <value>HBO.xml</value>
    <value>Sportv.xml</value>
    </param>
    <param access="1" constrainttype="INT_CHOICE"
    name="ChannelTable" oid="0x9" precision="0" strvalue="0"
    type="INT16" value="0" widget="default">
    <constraint key="7">Canal</constraint>
    <constraint key="8">Datafile</constraint>
    </param>
    <param access="1" constraint="0.0;100.0;0.0;100.0;1"
    constrainttype="INT_STEP_RANGE" name="squadSize"
    oid="0xA" precision="0" strvalue="4" type="INT16"
    value="4" widget="default"/>
    <param access="1" constraint="1.0;20.0;1.0;20.0;1"
    constrainttype="INT_STEP_RANGE" name="canal" oid="0xB"
    precision="0" strvalue="3" type="INT16" value="3" widget="default"/>
    <param access="1" constrainttype="INT_NULL"
    name="UNCChannelNumber" oid="0x100" precision="0"
    strvalue="0" type="INT16_ARRAY" value="0" widget="default"/>

    <param access="1" maxlength="0" name="UNCChannelNameFirst"
    oid="0x101" precision="0" type="STRING_ARRAY" widget="default">
    <value>blank</value>
    </param>
    <statsmenu menuid="0" name="status"/>

     

     

     

     

     


    #DashBoard


  • 14.  RE: XML parsing

    Posted 04-20-2020 18:42

    first thing you need to do is go into edit mode, double click on an empty space of your panel. Then on the source tab, add this look up tag under at the top of your <meta> tag, and leave the rest unchanged with <params> tag below it:

    <lookup id="constants">
    <entry key="filepath">Channel.xml</entry>
    </lookup>


    #DashBoard


  • 15.  RE: XML parsing

    Posted 04-20-2020 18:50

    Ok, 

    It's done!


    #DashBoard


  • 16.  RE: XML parsing

    Posted 04-20-2020 19:03

    now, when u hit xpath, does it show all your channels and datafiles?


    #DashBoard


  • 17.  RE: XML parsing

    Posted 04-20-2020 19:13

    Yes, when I clicked Init button and after that ,Xpath,  my channels and datafiles appear to me. Only the other table cointaining other information about the channels (time, number, film....), keeps showing the early problem.


    #DashBoard


  • 18.  RE: XML parsing

    Posted 04-20-2020 19:24

    ok. thats good. the error is happening on this line of code then:

    params.setValue(0x9, 0, 0); // Channel = 0 (triggers on change)

    and i think there are errors when you click on those channels, but we'll get to that.


    #DashBoard


  • 19.  RE: XML parsing

    Posted 04-20-2020 19:36

    Ok, In this line I only had  changed the initial parameters to my parameters. How,now, we know where the problem is, what you think I should do? 

    Is advisable delete this code line or replaced it to another? 


    #DashBoard


  • 20.  RE: XML parsing

    Posted 04-20-2020 20:41

    sorry. i got busy.

    no. don't delete it. i was only half correct. this line of code is not actually where the error is occuring. all this is doing is selecting the index 0 of the 0x9 parameter. but that triggers another action. that action can be found by double clicking on the canal table while in edit mode. im still troubleshooting it, but the funny part is that if you select HBO, it works. the other two do not.


    #DashBoard


  • 21.  RE: XML parsing

    Posted 04-20-2020 21:38

    Ok, relax.

    So, I won't edit any part of the code till you find the root of the problem, right?


    #DashBoard


  • 22.  RE: XML parsing

    Posted 04-21-2020 03:22

    ok. i got the xpath button working. i'm going to let you finish up with the getTag button. i have a few pieces of advice first. 1-name everything (variables, parameters, and tags in xml) with very descriptive names (feel free to rename what i renamed. i actually think the xml tags and attributes can be named more logical. just remember if you rename them, then you have to rename it in your panel code too, but you can search to make it easier). 2-use lots and lots of comments in your code. 3-use the debug window and use a lot of this debug code here:

    ogscript.debug('this the value of my variable1: ' + variable1);

    all this might take some time to do BUT it saves you a ton of time when it comes to debugging, cause you know what is going on and where to find your problems.

    anyway, after i cleaned up the xml files, the parameter names and the xpath button and the canal table task, these were the problems:

    1-you were calling xml attributes by the wrong name in your script. again practicing good naming would have prevented this.

    2-there was an "&" symbol in your xml code for telecine.xml, which has to be escaped, bc xml thinks its something other than just the name of your tv show. i just wrote it out for you as "and", but you could find that out online how to escape special characters if you choose to. this was a little tricky to figure out, but i code with a nice, but free, text editor, sublime text, and it highlighted that symbol, so i knew something was wrong.

    heres the code. good luck.

    channels.xml:

    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <channels name="EPL">
    <channel name="Telecine" filename="telecine.xml"/>
    <channel name="HBO" filename="hbo.xml"/>
    <channel name="Sportstv" filename="sportstv.xml"/>
    </channels>

    telecine.xml

    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <channel name="Telecine">
    <subChannels>
    <subCh numero="653" canal="Telecine Pipoca" name="Shaw and Robs" horario="10"/>
    <subCh numero="654" canal="Telecine Action" name="Jhon Wick" horario="14"/>
    <subCh numero="655" canal="Telecine Premium" name="007 Skyfall" horario="16"/>
    <subCh numero="656" canal="Telecine Cult" name="Titanic" horario="18"/>
    </subChannels>
    </channel>

    hbo.xml

    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <channel name="HBO">
    <subChannels>
    <subCh numero="753" canal="HBO1" name="Dr. Estranho" horario="9"/>
    <subCh numero="754" canal="HBO2" name="Preto ou Branco" horario="11"/>
    <subCh numero="755" canal="HBO PLUS" name="Eu e as Mulheres" horario="21"/>
    <subCh numero="756" canal="HBO Family" name="Homem Aranha" horario="23"/>
    </subChannels>
    </channel>

    sportstv.xml

    <channel name="Sportstv">
    <subChannels>
    <subCh numero="553" canal="Sportstv1" name="Sportstv News" horario="8"/>
    <subCh numero="554" canal="Sportstv2" name="Redação Sportstv" horario="13"/>
    <subCh numero="555" canal="Sportstv3" name="Sportstv Action" horario="8"/>
    <subCh numero="556" canal="Sportstv4" name="Redação Highlights" horario="13"/>
    </subChannels>
    </channel>

    gridfile.grid

    <abs contexttype="opengear" id="_top" keepalive="false">
    <meta>
    <lookup id="constants">
    <entry key="filepath">Channels.xml</entry>
    </lookup>
    <params>
    <param access="1" constrainttype="INT_CHOICE" name="canalTable" oid="0x9" precision="0" type="INT16" value="0" widget="default">
    <constraint key="7">Canals</constraint>
    <constraint key="8">FilePaths</constraint>
    </param>
    <param access="1" maxlength="0" name="ChannelsCineName" oid="0x2" precision="0" type="STRING_ARRAY" widget="default">
    <value>blank</value>
    <value>blank</value>
    <value>blank</value>
    <value>blank</value>
    </param>
    <param access="1" constrainttype="INT_NULL" name="ChannelsHorario" oid="0x5" precision="0" type="INT16_ARRAY" value="0;0;0;0" widget="default"/>
    <param access="1" maxlength="0" name="ChannelsFilme" oid="0x6" precision="0" type="STRING_ARRAY" widget="default">
    <value>blank</value>
    <value>blank</value>
    <value>blank</value>
    <value>blank</value>
    </param>
    <param access="1" constrainttype="INT_NULL" name="ChannelsNumero" oid="0x3" precision="0" type="INT16_ARRAY" value="0;0;0;0" widget="label"/>
    <param access="1" constrainttype="INT_CHOICE" name="ChannelsTable" oid="0x4" precision="0" type="INT16" value="0" widget="table">
    <constraint key="3">Numero</constraint>
    <constraint key="2">CineName</constraint>
    <constraint key="6">Filme</constraint>
    <constraint key="5">Horario</constraint>
    </param>
    <param access="1" constrainttype="INT_NULL" name="ChannelsSize" oid="0xA" precision="0" type="INT16" value="0" widget="default"/>
    <param access="1" maxlength="0" name="canalFilePaths" oid="0x8" precision="0" type="STRING_ARRAY" widget="default">
    <value>telecine.xml</value>
    <value>hbo.xml</value>
    <value>sportstv.xml</value>
    </param>
    <param access="1" maxlength="0" name="canalCanals" oid="0x7" precision="0" type="STRING_ARRAY" widget="default">
    <value>Telecine</value>
    <value>HBO</value>
    <value>Sportv</value>
    </param>
    <param access="1" constrainttype="INT_NULL" name="canalSize" oid="0xB" precision="0" type="INT16" value="0" widget="default"/>
    <param access="1" maxlength="0" name="UNCChannelNameFirst" oid="0x101" precision="0" type="STRING_ARRAY" widget="default">
    <value>blank</value>
    </param>
    <param access="1" constrainttype="INT_NULL" name="UNCChannelNumber" oid="0x100" precision="0" type="INT16_ARRAY" value="0" widget="default"/>
    </params>
    </meta>
    <drawer height="263" left="38" style="bg-u:file:/C:/Users/joaoa/OneDrive/Pictures/dashboard/telecine.jpg;bg-align:center;bdr:round;" tabfill="none" top="159" width="420"/>
    <split height="481" left="522" orientation="horizontal" top="118" width="837">
    <abs weight="0.5">
    <param expand="true" height="238" left="79" oid="0x9" scroll="true" showlabel="false" top="89" widget="table" width="322">
    <task tasktype="ogscript">var filepath = params.getValue(8,params.getValue(9,0)); //var for name of file of selected canal
    ogscript.debug ("Canal datafile: " + filepath);
    ogscript.rename ('subChLabel', params.getValue(7, params.getValue(9,0))); //rename something. i really dont know*****************************
    var XMLDoc = ogscript.parseXML(filepath); //variable of parsed xml from the selected canal xml file
    if (XMLDoc == null) {
    ogscript.debug('Failed to read team data file');
    } else {
    // clear out the existing squad data
    ogscript.debug('Parsing XML');
    var found = XMLDoc.getElementsByTagName('subCh');
    var tagLimit = found.length;
    //loop through the number of tags and reset them
    for (var i = 0; i &lt; tagLimit; ++i) {
    params.setValue(2, i, "blank");
    params.setValue(3, i, 0);
    params.setValue(5, i, 0);
    params.setValue(6, i, "blank");
    }
    ogscript.debug('search found ' + tagLimit + ' items');
    params.setValue(0xa, 0, tagLimit);
    for (var i = 0; i &lt; found.length; i++) {
    var node = found.item(i);
    var numero = node.getAttribute('numero');
    var cinename = node.getAttribute('canal');
    var filme = node.getAttribute('name');
    var time = node.getAttribute('horario');
    ogscript.debug(i + ": " + numero + ", " + cinename + ", " + filme + ", " + time);
    params.setValue(3, i, Number(numero));
    params.setValue(2, i, cinename);
    params.setValue(5, i, time);
    params.setValue(6, i, filme);
    }
    }</task>
    </param>
    </abs>
    <abs style="txt-align:center;">
    <param anchor="west" bottom="359" expand="true" fill="both" id="table" left="0" name="Programação" oid="0x4" right="69" scroll="true" showlabel="false" top="0" weightx="1.0" weighty="1.0">
    <task tasktype="ogscript"/>
    </param>
    <table height="120" left="21" style="bdr:etched;" top="316" width="389">
    <tr>
    <button buttontype="push" colspan="1" fill="both" height="120" left="443" name="XPath" rowspan="1" top="85" weightx="1.0" weighty="1.0" width="136">
    <task tasktype="ogscript">var filepath = ogscript.getPrivateString('constants','filepath'); //get filepath for xml file for list of channels
    ogscript.debug('Reading XML file: ' + filepath);
    XMLDoc = ogscript.parseXML(filepath); //parse the xml of that filepath
    if (XMLDoc == null) {
    ogscript.debug('Failed to read file');
    } else {
    ogscript.debug('Parsing XML');
    var found = ogscript.runXPath('/channels/channel', XMLDoc); //variable found for seperating only channels data
    ogscript.debug('search found ' + found.length + ' items');
    var canalLimit = found.length; //variable for the number of channels
    params.setValue(0xB, 0, canalLimit); // set the channel size parameter, canais = length
    //loop through channels to populate canal table
    for (var i = 0; i &lt; canalLimit; i++) {
    var node = found.item(i); //variable node for each item(channel) found
    var channelName = node.getAttribute('name'); //variable for name of channel data
    var fileName = node.getAttribute('filename'); //variable for filename data
    ogscript.debug(i + ": " + channelName + ", " + fileName);
    params.setValue(7, i, channelName); //setup canal table, canalNames[i] = canalname
    params.setValue(8, i, fileName); //setup canal table, canalFilePaths[i] = filename
    }
    params.setValue(0x9, 0, 0); // Channel = 0 (triggers on change)

    }</task>
    </button>
    <button buttontype="push" colspan="1" fill="both" height="120" left="443" name="Tag Gets" rowspan="1" top="85" weightx="1.0" weighty="1.0" width="136">
    <task tasktype="ogscript">var filepath = ogscript.getPrivateString('constants','filepath');
    var XMLDoc;
    ogscript.debug('Reading XML file: ' + filepath);
    XMLDoc = ogscript.parseXML(filepath);
    if (XMLDoc == null) {
    ogscript.debug('Failed to read file');
    } else {
    ogscript.debug('Parsing XML');
    var found=XMLDoc.getElementsByTagName('canal');
    ogscript.debug('search found ' + found.length + ' items');
    params.setValue(0xb, 0, found.length); // canais = length
    for (var i = 0; i &lt; found.length; i++) {
    var node = found.item(i);
    var canalname = node.getAttribute('name');
    var filename = node.getAttribute('filename');
    ogscript.debug(i + ": " + canalname + ", " + filename);
    params.setValue(7, i, canalname); // canaisNames[i] = canaisname
    params.setValue(8, i, filenema); // canalFilePaths[i] = filecanais
    }
    params.setValue(0x9, 0, 0); // ChannelTable = 0 (triggers onchange)

    }</task>
    </button>
    <button buttontype="push" colspan="1" fill="both" height="120" left="0" name="Init" top="0" weightx="1.0" weighty="1.0" width="136">
    <task tasktype="ogscript">var squadSize = params.getValue(0xa, 0);
    var canal = params.getValue(0xb, 0);

    for (var i = 0; i &lt; squadSize; i++)
    {
    params.setValue(0x2, i, "blank");
    params.setValue(0x3, i, 0);
    params.setValue(0x5, i, "0");
    params.setValue(0x6, i, "blank");
    }
    for (var i = 0; i &lt; canal; ++i)
    {
    params.setValue(0x7, i, "blank");
    params.setValue(0x8, i, "blank");
    }
    params.setValue(0xa, 0, 0);
    params.setValue(0xb, 0, 0);
    ogscript.rename('squadLabel', 'blank');</task>
    </button>
    </tr>
    </table>
    </abs>
    </split>
    </abs>


    #DashBoard


  • 23.  RE: XML parsing

    Posted 04-21-2020 15:14

    Ok, 

    Thank you very much for spend tour time solving my problem. I'll test this code.

    So, now I should correct code of the other buttons, right? And about XML archives....what application do you use to genegate them? Beacuse I had used 'Notepad' windowns app to did that. I don't know if it's better solution as possible.

     

     


    #DashBoard


  • 24.  RE: XML parsing

    Posted 04-21-2020 15:58

    no problem. we all need help from time to time. and yes, the getTag button still needs to be programmed. as for creating xml files, notepad works, BUT i recommend that you try sublime text. it's free, and it will color code your tags and attributes and other keywords, which will help you to visually keep your code organized. it helped me find that "&" error which if you didn't know what you were looking for, that might have gone unnoticed for quite some time, especially if you were using notepad. sublime text also has some really nice features, like block highlighting, searching by regular expressions, etc. im not sure if it does any software assisted coding, like closing tags that you open, which could be helpful i suppose. a lot of times these features are in the paid developer software packages.


    #DashBoard