Facility Control

 View Only
  • 1.  XML Parsing in Dashboard

    Posted 11-07-2022 14:37
    Hello,
    I'm attempting to control another device through a REST API using Dashboard. I must obtain a authentication token from the device before being able to send any other commands by issuing a login command.

    Here is the response from the device after a login command. 

    <?xml version="1.0" encoding="UTF-8"?><api_response><version>10</version><timestamp>2022-11-07 12:13:46</timestamp><success>1</success><token>somelongauthtokenstringhere12345</token></api_response>

    I have this portion working in dashboard already and am working on the callback function to parse/extract the token and stick it in an object or possibly parameter to recall later. Essentially I am trying to just extract the data in the <token> tag, and I'm unsure of the syntax to use to do it.

    Any help would be appreciated.
    Thanks

    ------------------------------
    Ryan McCarthy
    Broadcast Engineer
    UnitedHealth Group
    ------------------------------


  • 2.  RE: XML Parsing in Dashboard

    Posted 11-07-2022 17:00
    Hi Ryan
    If you are only getting one <token/> tag in your response, you can very quickly parse the XML and get a NodeList of all token tags:
    function getToken(result)
    {
       if (result == null)
       {
          return;
       }
    
       var xml = ogscript.parseXML(result);
       var tokens = xml.getElementsByTagName('token');
       return tokens.item(0).getTextContent();
    }
    
    var resultStr = '<?xml version="1.0" encoding="UTF-8"?><api_response><version>10</version><timestamp>2022-11-07 12:13:46</timestamp><success>1</success><token>somelongauthtokenstringhere12345</token></api_response>'
    ogscript.debug(getToken(resultStr));​


    ------------------------------
    James Peltzer
    Ross Video
    ------------------------------



  • 3.  RE: XML Parsing in Dashboard

    Posted 11-07-2022 17:28
    Beautiful, exactly what I needed.

    Thanks!

    ------------------------------
    Ryan McCarthy
    Broadcast Engineer
    UnitedHealth Group
    ------------------------------