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 < 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 < 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 < 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 < 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 < 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 < 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