How do I display this XML document?

Effectively I’m trying to display this data (actually combined data from multiple channels but it’s the same idea):

https://www.youtube.com/feeds/videos.xml?user=YouTube

I used something I found on w3schools:

<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","https://www.youtube.com/feeds/videos.xml?user=YouTube",false);
xmlhttp.send();
xmlDoc=xmlhttp.responseXML; 

var x=xmlDoc.getElementsByTagName("item");
for (i=0;i<x.length;i++)
  { 
  document.write("<tr><td>");
  document.write(x[i].getElementsByTagName("pubDate")    [0].childNodes[0].nodeValue);
  document.write("</td><td>");
  document.write(x[i].getElementsByTagName("author")    [0].childNodes[0].nodeValue);
  document.write("</td><td>");
  document.write(x[i].getElementsByTagName("views")[0].childNodes[0].nodeValue);
  document.write("</td><td>");
  document.write(x[i].getElementsByTagName("author")    [0].childNodes[0].nodeValue);
  document.write("</td><td>");
  document.write(x[i].getElementsByTagName("media:description")    [0].childNodes[0].nodeValue);
  document.write("</td><td>");
  document.write(x[i].getElementsByTagName("link")[0].childNodes[0].nodeValue);
  document.write("</td></tr>");
  }
document.write("</table>");
</script>

I also need to display other data like “media:description” but I can’t figure out how, or worse:

<media:community>
<media:starRating count="45552" average="4.67" min="1" max="5"/>
<media:statistics views="4641380"/>

How can I display this?


Source: xml

Leave a Reply