Converting a Microsoft XML file to <ul>

Posted by on Feb 7, 2011 in Code, Snippets | No Comments

I modified a W3Schools script to get this JavaScript snippet because I needed to add a large excel table to a web-page as an unordered list. I set up a single column table in Excel and exported the table as an XML file called “list” and ran this code in the browser. Hope it helps somebody:


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","list.xml",false);
xmlhttp.send();
xmlDoc=xmlhttp.responseXML; 

document.write("<ul id='navlist'>");
var x=xmlDoc.getElementsByTagName("w:r");
for (i=0;i<x.length;i++)
  {
  document.write("<li><a href='#'>");
  document.write(x[i].getElementsByTagName("w:t")[0].childNodes[0].nodeValue);
  document.write("</a></li>");
  }
document.write("</ul>");

Leave a Reply