/    Sign up×
Community /Pin to ProfileBookmark

javascript read from xml file when new xml is created

Hi guys,

I am trying to work through some code to create an html page that will read an xml file and update the text of two span tags on my page. The problem I have is that every 20 seconds the xml file is reloaded with new data. I am thinking some kind of AJAX but I am not exactly sure how to do this.

my xml file looks like this

<speed>
<upload></upload>
<download></download>
</speed>

thank you!

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@ajcool123authorAug 08.2008 — Note: I figured it out.

Here is my html file for future reference... Good Luck!

<html>

<head>

<script type="text/javascript">

function parseXML()

{

try //Internet Explorer

{

xmlDoc=new ActiveXObject("Microsoft.XMLDOM");

}

catch(e)

{

try //Firefox, Mozilla, Opera, etc.

{

xmlDoc=document.implementation.createDocument("","",null);

}

catch(e)

{

alert(e.message);

return;

}

}

xmlDoc.async=false;

if(xmlDoc.load("bandwidth.xml"))
{
document.getElementById("xml").innerHTML= 'XML Found';
}
else
{
document.getElementById("xml").innerHTML= 'XML Not Found';
}

// update bandwidth
document.getElementById("upload").innerHTML=xmlDoc.getElementsByTagName("upload")[0].childNodes[0].nodeValue;
document.getElementById("download").innerHTML=xmlDoc.getElementsByTagName("download")[0].childNodes[0].nodeValue;

// wait 10 seconds look for updated xml
setTimeout('parseXML()',10000);

}

</script>

</head>

<body onload="parseXML()">

<span id="xml" style="font-size: 24px; color: Black; font-style: bold"></span>

<br>

<br>

<span style="font-size: 16px;">UP:</span> <span id="upload" style="font-size: 24px; color: Green; font-style: bold">N/A</span>

<br>

<span style="font-size: 16px;">DN:</span> <span id="download" style="font-size: 24px; color: Green; font-style: bold">N/A</span>

</body>

</html>
Copy linkTweet thisAlerts:
@HoboScriptAug 08.2008 — You may want to use an interval for this.

<i>
</i>window.onload = function() { setInterval("parseXML()", 10000); }
Copy linkTweet thisAlerts:
@ajcool123authorAug 09.2008 — Thank you for your reply. How would the setInteval look in the code? Would this eliminate the need for the body onload event? I am not exactly sure where in the javascript I would be calling this.

Thank you for your help!
×

Success!

Help @ajcool123 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.13,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...