Jump to content

Need help with pulling XML data into HTML


Never Hide Gaming

Recommended Posts

Hello and thank you to anyone and everyone that responds. I am very new to XML and have done some of the tutorials, but I am having trouble getting the information to pull. The XML file is automatically updated by a website and I would like to pull information off of it to put on my own website.

 

First off, do I need to re-load the XML file on my site first? Someone said that I was going to have to do this but I am not sure how. I feel as though this could be the error that I am facing.

 

 

 

 

 

 

This is my XML file

 

 

<team cacheDate="Mon 8 Dec 2014, 10:22 PM CST">
<name>
<![CDATA[ Never Hide ]]>
</name>
<foundedDate timestamp="1396323803">Mon 31 Mar 2014, 10:43 PM CDT</foundedDate>
<reputation>Array</reputation>
<arena>Call of Duty: Ghosts</arena>
<platform>Xbox One</platform>
<currentStats>
<season>
</season>
<place>0</place>
<previousPlace>3717</previousPlace>
<matchesPlayed>14</matchesPlayed>
<wins>2</wins>
<losses>12</losses>
<winPercentage>0.143</winPercentage>
<gamesFor>8</gamesFor>
<gamesAgainst>22</gamesAgainst>
<shutouts>2</shutouts>
<streak>-5</streak>
<xp>0</xp>
<level>1</level>
<levelUp>1000</levelUp>
</currentStats>
<alltimeStats>
<matchesPlayed>18</matchesPlayed>
<wins>2</wins>
<losses>16</losses>
<winPercentage>0.111</winPercentage>
<gamesFor>8</gamesFor>
<gamesAgainst>31</gamesAgainst>
<shutouts>2</shutouts>
<streak>-5</streak>
<xp>0</xp>
</alltimeStats>
<roster>...</roster>
<recentMatches>
<match>
<date timestamp="1409732100">Wed 3 Sep 2014, 3:15 AM CDT</date>
<result>L</result>
<xp/>
<opponent>
<name>
<![CDATA[ Trip cappeddd ]]>
</name>
</opponent>
</match>
<match>
<date timestamp="1409728500">Wed 3 Sep 2014, 2:15 AM CDT</date>
<result>L</result>
<xp/>
<opponent>
<name>
<![CDATA[ Composure ]]>
</name>
</opponent>
</match>
<match>
<date timestamp="1409724900">Wed 3 Sep 2014, 1:15 AM CDT</date>
<result>L</result>
<xp/>
<opponent>
<name>
<![CDATA[ DingleBerry Pickers ]]>
</name>
</opponent>
</match>
<match>
<date timestamp="1409724000">Wed 3 Sep 2014, 1:00 AM CDT</date>
<result>L</result>
<xp/>
<opponent>
<name>
<![CDATA[ Bad News Bears ]]>
</name>
</opponent>
</match>
<match>
<date timestamp="1407733200">Mon 11 Aug 2014, 12:00 AM CDT</date>
<result>L</result>
<xp/>
<opponent>
<name>
<![CDATA[ The Savages and Nick ]]>
</name>
</opponent>
</match>
<match>
<date timestamp="1406777400">Wed 30 Jul 2014, 10:30 PM CDT</date>
<result>W</result>
<xp/>
<opponent>
<name>
<![CDATA[ osama bin laden squad ]]>
</name>
</opponent>
</match>
<match>
<date timestamp="1405926000">Mon 21 Jul 2014, 2:00 AM CDT</date>
<result>W</result>
<xp/>
<opponent>
<name>
<![CDATA[ Smoke Break ]]>
</name>
</opponent>
</match>
<match>
<date timestamp="1404633600">Sun 6 Jul 2014, 3:00 AM CDT</date>
<result>L</result>
<xp/>
<opponent>
<name>
<![CDATA[ Martins ego ]]>
</name>
</opponent>
</match>
<match>
<date timestamp="1404628200">Sun 6 Jul 2014, 1:30 AM CDT</date>
<result>L</result>
<xp/>
<opponent>
<name>
<![CDATA[ Insidious Cult ]]>
</name>
</opponent>
</match>
<match>
<date timestamp="1404437400">Thu 3 Jul 2014, 8:30 PM CDT</date>
<result>L</result>
<xp/>
<opponent>
<name>
<![CDATA[ HeaT $2.5k ]]>
</name>
</opponent>
</match>
</recentMatches>

 

</team>

http://gamebattles.majorleaguegaming.com/xboxone/call-of-duty-advanced-warfare/team/never-hide-gaming/stats.xml

 

This is the code that I am trying to use. If I can get one thing to actually pull, then I can figure the rest out. I have been using the Tryit Editor so far to test everything before populating my site.

<!DOCTYPE html><html><head><style>table, th, td {    border: 1px solid black;    border-collapse:collapse;}th, td {    padding: 5px;}</style></head><body><script>if (window.XMLHttpRequest)  {// code for IE7+, Firefox, Chrome, Opera, Safari  xmlhttp=new XMLHttpRequest();  }else  {// code for IE6, IE5  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");  }xmlhttp.open("GET","gamebattles.majorleaguegaming.com/xboxone/call-of-duty-ghosts/team/never-hide/stats.xml",false);xmlhttp.send();xmlDoc=xmlhttp.responseXML; document.write("<table><tr><th>Team</th><th>Result</th></tr>");var x=xmlDoc.getElementsByTagName("recentMatches");for (i=0;i<x.length;i++)  {   document.write("<tr><td>");  document.write(x[i].getElementsByTagName("name")[0].childNodes[0].nodeValue);  document.write("</td><td>");  document.write(x[i].getElementsByTagName("result")[0].childNodes[0].nodeValue);  document.write("</td></tr>");  }document.write("</table>");</script></body></html>

Sorry that this is so long and drawn out, but thank you very much in advance.

 

 

Link to comment
Share on other sites

You're missing the http:// in the URL on this line of code:

xmlhttp.open("GET","gamebattles.majorleaguegaming.com/xboxone/call-of-duty-ghosts/team/never-hide/stats.xml",false);

That is a necessary but not sufficient condition for this to work. The other necessary condition is that their server sends a response with a header indicating that cross-domain AJAX requests are allowed. If they are not, then you can't use AJAX to load this data.

 

Learn more about cross-domain requests here: https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...