Read in text/xml from a remote webserver using web object

Aug 28, 2021

Rather than locally packaging an xml/text file within the SCORM object, we are hoping to maintain the text/xml in a global location on a website. Our goal is to be able to change the content/value of the xml/text file on the website instead of changing it locally and then having to re-send SCORM content to our customers.

Is it possible to point to an XML file on a website (for example):

www.mywebsite.com/exercise.XML

and read the contents and load that into a variable in SL360?

Many thanks in advance for your assistance.

David

1 Reply
David Hirsch

If it helps, I am adapting some Javascript that works for a local file but it does not seem to work:

var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
getValues(this);
}
};

let url1 = new URL('https://www.myserver.com/values.xml');
alert (url1);

xhttp.open("GET", url1, true);
xhttp.send();

xhttp.onload = function() {
alert(`Loaded: ${xhttp.status} ${xhttp.response}`);
};

xhttp.onerror = function() { // only triggers if the request couldn't be made at all
alert(`Network Error`);
};

function getValues(xml) {
var player = GetPlayer();
var xmlDoc = xml.responseXML;
var x = xmlDoc.getElementsByTagName('db');
player.SetVar("Value1", x[0].getAttribute('value'));
player.SetVar("Value2", x[1].getAttribute('value'));
player.SetVar("Value3", x[2].getAttribute('value'));
}