Facility Control

 View Only
  • 1.  XML Roster Tables

    Posted 06-11-2015 18:15

    I should preface this by saying I am a newbie to coding. What I am essentially looking to do is to create a set of tables, like the ones in the XML Example Project to load rosters into my project.

    What I have done right now to try to deconstruct and reconstruct it is to make my own custom-panel, but try using the XML files from the example project (copied over into the folder where my current panel is).

    Right now I have started with just the table that displays the Team Name and Datafile.

    I have created the following parameters

    teamName (0x3)

    teamFilePath (0x4)

    teamTable (0x2, the table works fine and displays the above two parameters with their initial "blank" values)

    teams (0xB, An integer range constraint whose purpose I am not sure of, but it is in the code for the Xpath button)

    I have then made a button, to which I have pretty much copied the code from the Xpath button in the example project:

    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('/league/team', XMLDoc);

    ogscript.debug('search found ' + found.length + ' items');

    params.setValue(0xb, 0, found.length); // teams = length

    for (var i = 0; i < found.length; i++) {

    var node = found.item(i);

    var teamname = node.getAttribute('name');

    var filename = node.getAttribute('filename');

    ogscript.debug(i + ": " + teamname + ", " + filename);

    params.setValue(3, i, teamname); // teamNames[i] = teamname

    params.setValue(4, i, filename); // teamFilePaths[i] = filename

    }

    params.setValue(0x2, 0, 0); // league = 0 (triggers on change)

    }

    The only changes being the parameter numbers.

    Trying to use it, though, my parameters remain with their default values and I am not sure why. There is probably a really simple explanation, but as I said I am relatively new to this. There are lines in that code whose actions/purpose I am not even sure of.



  • 2.  RE: XML Roster Tables

    Posted 06-11-2015 18:25

    The sample XML file I am working with, from the sample project:

    ?xml version="1.0" encoding="UTF-8" standalone="yes"?

    league name="EPL"

    team name="Manchester United F.C." filename="ManU.xml"/

    team name="Chelsea F.C." filename="Chelsea.xml"/

    team name="Liverpool F.C." filename="Liverpool.xml"/

    /league

    (there are < > brackets surrounding each line, but they mess things up when copying it here.)

    The plan, once I actually get this working would be to replace and add teams from the leagues relevant to my project.


    #DashBoard


  • 3.  RE: XML Roster Tables

    Posted 06-12-2015 19:31
    The first step would be to verify that the script is in fact being read and executing completely.

    It appears that there are a number of debug lines already in the code. Are they being printed to the debug information view?(views->"openGear Debug Information")

    #DashBoard


  • 4.  RE: XML Roster Tables

    Posted 06-15-2015 16:31
    Yeah, I tried opening the debug up and it says the following:

    10:30:08:451: Reading XML file: null

    10:30:08:451: Failed to read file

    The thing is I am not sure why it would fail to read, when everything is following the template of the example project which reads with no issues.

    #DashBoard


  • 5.  RE: XML Roster Tables

    Posted 06-15-2015 16:37

    Based on that, you're missing a `` table with an entry for the filepath.

    You don't necessarily have to do this to read your file (that's just how the example you were using did it).

    Start with this:

    `

    var filepath = 'PUT_FILE_NAME_HERE.xml';

    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('/league/team', XMLDoc);

    ogscript.debug('search found ' + found.length + ' items');

    params.setValue(0xb, 0, found.length); // teams = length

    for (var i = 0; i < found.length; i++) {

    var node = found.item(i);

    var teamname = node.getAttribute('name');

    var filename = node.getAttribute('filename');

    ogscript.debug(i + ": "� + teamname + ", "� + filename);

    params.setValue(3, i, teamname); // teamNames[i] = teamname

    params.setValue(4, i, filename); // teamFilePaths[i] = filename

    }

    params.setValue(0Á—2, 0, 0); // league = 0 (triggers on change)

    }`

    #DashBoard


  • 6.  RE: XML Roster Tables

    Posted 06-15-2015 16:56
    Hmmm, I thought I had tried that already, but apparently not.

    Replacing

    var filepath = ogscript.getPrivateString('constants','filepath');

    with

    var filepath = 'league.xml';

    Got it to work. That was one thing about the code that had confused me, I wasn't sure where that first line was looking and was scratching my head over it.

    Thanks for the help.

    #DashBoard