Facility Control

 View Only
  • 1.  Reading XML Data into player dropdowns

    Posted 06-01-2017 12:56

    Hi Gentlemen

    I have attached a picture to assist in understanding my query.

    As in the picture, I have a player dropdown.

    This dropdown represents the players number and name.

    Would it be possible to enter all player info into XML format and have this dropdown read it?



  • 2.  RE: Reading XML Data into player dropdowns

    Posted 06-01-2017 18:42

    Hi Dennis.
    Here is an example of how to load this kind of data:

    <abs contexttype="opengear" style="">
       <meta>
          <params>
             <param access="1" constrainttype="INT_CHOICE" name="Constraint From XML" oid="Constraint_From_XML" precision="0" type="INT32" value="0" widget="combo">
                <constraint key="0">Nothing</constraint>
             </param>
          </params>
          <ogscript handles="onload">var newConstraint = params.createIntChoiceConstraint(["Nothing"]);
    params.replaceConstraint('Constraint_From_XML', newConstraint);</ogscript>
       </meta>
       <param expand="true" height="90" left="32" oid="Constraint_From_XML" top="48" width="626"/>
       <button buttontype="push" height="95" left="673" name="Load" top="47" width="183">
          <task tasktype="ogscript">var xmlDocument = ogscript.parseXML('data.xml');         //Parse the XML
    var nodeList = xmlDocument.getElementsByTagName("team"); //Get the tags we want to include in the constraint
    
    var constraintData = [];   //Placeholder for the new constraint data
    
    if (constraintData.length == 0)  //Placeholder if we don't have anything (OPTIONAL)
    {
       constraintData.push({"key": 0, "value": "Nothing"});
    }
    
    for (var i = 0; i &lt; nodeList.getLength(); i++)           //Loop through each tag we found
    {
       var node = nodeList.item(i);                          //Get the node
       constraintData.push({"key": parseInt(node.getAttribute("ID")), "value": node.getAttribute("name")});  //Push the key/value pair
    }
    
    
    var constraint = params.createIntChoiceConstraint(constraintData);   //Create the constraint
    params.replaceConstraint("Constraint_From_XML", constraint);         //Replace the constraint</task>
       </button>
    </abs>

    The relevant bit is attached to the button:

    var xmlDocument = ogscript.parseXML('data.xml');         //Parse the XML
    var nodeList = xmlDocument.getElementsByTagName("team"); //Get the tags we want to include in the constraint
    
    var constraintData = [];   //Placeholder for the new constraint data
    
    if (constraintData.length == 0)  //Placeholder if we don't have anything (OPTIONAL)
    {
       constraintData.push({"key": 0, "value": "Nothing"});
    }
    
    for (var i = 0; i < nodeList.getLength(); i++)           //Loop through each tag we found
    {
       var node = nodeList.item(i);                          //Get the node
       constraintData.push({"key": parseInt(node.getAttribute("ID")), "value": node.getAttribute("name")});  //Push the key/value pair
    }
    
    
    var constraint = params.createIntChoiceConstraint(constraintData);   //Create the constraint
    params.replaceConstraint("Constraint_From_XML", constraint);         //Replace the constraint

    Here is the example XML data I was working with (I had it saved in a file called data.xml)

    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <teams>
        <team ID="1" name="Red Team"/>
        <team ID="2" name="Blue Team"/>
        <team ID="3" name="Green Team"/>
    </teams>
    

    #DashBoard


  • 3.  RE: Reading XML Data into player dropdowns

    Posted 06-01-2017 18:46
    Thank you James. I will try this
    #DashBoard


  • 4.  RE: Reading XML Data into player dropdowns

    Posted 06-02-2017 10:57

    Hi James

    Thank you for this. It works very well. I have a related question, please see the images.

    I have created a separate tab to load players for each match, I now would like to add the players to my main scoring TAB but as READ ONLY bars. For some reason this is not possible, do you have any suggestions?

    Picture 1: Showing how I have created my dropdowns which function well

    Picture 2: My parameter window does not show the parameters.

    Picture 3: Where I would like to put all players in 'Read only'


    #DashBoard