Matty, you should be aware that you have to declare your onreadystatechange event BEFORE you call xml.load(). So, either you simply place the contents of the createXml function in the timer event, or you add the callback function as a parameter to the createXml function and assign it to onreadystatechange in the createXml function.
I already explained this in
Mattike's reply to XMLHTTP Not Loading After Save. The thing is that if you declare it after the load() function, there's a (small) chance that the asynchronous XML loading is faster than the process of the script.
code:
...
function createXml(url, funcReadyStateChange) {
Interop.Call('wininet.dll', 'DeleteUrlCacheEntryW', url);
xml = new ActiveXObject('Microsoft.XMLDOM');
xml.async = true;
xml.onreadystatechange = funcReadyStateChange;
xml.load(url);
return xml;
}
function OnEvent_Timer() {
var xml = createXml('http://bbc-hackday.dyndns.org/tracks/radio1.rss', function() {
if (xml.readyState === 4)
var newPsm = xml.selectSingleNode('//rss/channel/item/dc:creator').text+' - '+xml.selectSingleNode('//rss/channel/item/dc:title').text;
Debug.Trace(newPsm);
if (sPsm !== newPsm) {
Messenger.MyPersonalMessage = newPsm;
sPsm = newPsm;
}
xml = null;
});
MsgPlus.AddTimer('grabSong', 60000); // one minute
}
Also, I don't really know for the XMLDOM but I think you should also check the xml.status to see if it equals 200 (xml.status === 200) in the event. I don't really know if it functions like the XMLHTTP, but the xml.readyState documentation says:
quote:
Originally posted by DevGuru XML DOM :: readyState
- ...
- COMPLETED(4)
the document has been completely loaded, successfully or unsuccessfully.