I'm new to code development and I'm trying to build a project to help me retain the skills I have learned. In doing so, I've hit a snag.
I am trying to pull a couple of attributes from nodes in an XML file but having trouble getting to what I need. I need to be able to pull the "number" from the node parent and the team "code" for each team listed in the node. The number of teams fluctuate between 2 and 6. Here's a sample of the XML.
My code is below. When it runs, it will get the bye week data but it won't load the teams. Several posts that I've read have had a similar issue but with some other technology or data structure in place that didn't apply to what I'm working with here (as far as I could tell). Any help would be appreciated.
<!DOCTYPE html>
<html>
<head>
<title>Bye Week</title>
<script>
var xmlhttp;
window.onload = function()
{
var url = "https://www.fantasyfootballnerd.com/service/byes/xml/test/";
xmlhttp = new XMLHttpRequest();
xmlhttp.open("GET", url, true);
xmlhttp.onreadystatechange = byeWeeks;
xmlhttp.send();
}
function byeWeeks()
{
if(xmlhttp.readyState==4 && xmlhttp.status==200)
{
var theXML = xmlhttp.responseXML.documentElement.getElementsByTagName('Week');
for(var i = 0; i < theXML.length; i++)
{
var week = theXML[i].getAttribute('number');
var team = theXML[i].getElementsByTagName('Team');
var out = "<b>" + team + "</b><br/>";
out += "Bye Week: " + week + "<br/>";
console.group('Output for ' + team);
console.log('Bye Week: ' + week);
console.log();
console.groupEnd();
document.getElementById('result').innerHTML += out
}
}
}
</script>
</head>
<body>
<div id="result"></div>
</body>
</html>