gsnedders
12-15-2005, 05:37 PM
I'm having problems getting the script to work, while I get the list cleared out, and blank <li> element created, it has nothing within it.
function loadXMLDoc(url)
{
req = new XMLHttpRequest();
req.onreadystatechange = processReqChange;
req.open("GET", url, true);
req.send(null);
}
function processReqChange()
{
// only if req shows "loaded"
if (req.readyState == 4)
{
// only if "OK"
if (req.status == 200)
{
clearPlayers();
buildPlayers();
}
else
{
alert("There was a problem retrieving the XML data:\n" + req.statusText);
}
}
}
function getElementTextNS(prefix, local, parentElem, index)
{
var result = "";
result = parentElem.getElementsByTagName(local)[index];
if (result)
{
if (result.childNodes.length > 1)
{
return result.childNodes[1].nodeValue;
}
else
{
return result.firstChild.nodeValue;
}
}
else
{
return "n/a";
}
}
function clearPlayers()
{
var ul = document.getElementById("players");
while (ul.firstChild)
{
ul.removeChild(ul.firstChild);
}
}
function buildPlayers() {
var players = document.getElementById("players");
var items = req.responseXML.getElementsByTagName("item");
for (var i = 0; i < items.length; i++) {
var player = document.createElement("li");
players.insertBefore(player, players.firstChild);
player.firstChild.nodeValue = getElementTextNS("", "title", items[i], 0);
}
}
function load()
{
loadXMLDoc("http://stats.bzflag.org/rss.php?feed=players&server=viper.pimpi.org:5158&order=score");
}
window.onload = load;
and the XHTML
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>XHTML Example</title>
<script type="text/javascript" src="bzflag.js"></script>
</head>
<body>
<ul id="players">
<li>Blah</li>
</ul>
</body>
</html>
function loadXMLDoc(url)
{
req = new XMLHttpRequest();
req.onreadystatechange = processReqChange;
req.open("GET", url, true);
req.send(null);
}
function processReqChange()
{
// only if req shows "loaded"
if (req.readyState == 4)
{
// only if "OK"
if (req.status == 200)
{
clearPlayers();
buildPlayers();
}
else
{
alert("There was a problem retrieving the XML data:\n" + req.statusText);
}
}
}
function getElementTextNS(prefix, local, parentElem, index)
{
var result = "";
result = parentElem.getElementsByTagName(local)[index];
if (result)
{
if (result.childNodes.length > 1)
{
return result.childNodes[1].nodeValue;
}
else
{
return result.firstChild.nodeValue;
}
}
else
{
return "n/a";
}
}
function clearPlayers()
{
var ul = document.getElementById("players");
while (ul.firstChild)
{
ul.removeChild(ul.firstChild);
}
}
function buildPlayers() {
var players = document.getElementById("players");
var items = req.responseXML.getElementsByTagName("item");
for (var i = 0; i < items.length; i++) {
var player = document.createElement("li");
players.insertBefore(player, players.firstChild);
player.firstChild.nodeValue = getElementTextNS("", "title", items[i], 0);
}
}
function load()
{
loadXMLDoc("http://stats.bzflag.org/rss.php?feed=players&server=viper.pimpi.org:5158&order=score");
}
window.onload = load;
and the XHTML
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>XHTML Example</title>
<script type="text/javascript" src="bzflag.js"></script>
</head>
<body>
<ul id="players">
<li>Blah</li>
</ul>
</body>
</html>