0

Whats the easiest way I can take a folder containing XML files and display each one in its own table on a webpage. I have this code which can read one XML file when a button is clicked but would like to make it take all the XML files in a folder?

<script>
function loadXMLDoc() {
  var xmlhttp = new XMLHttpRequest();
  xmlhttp.onreadystatechange = function() {
    if (this.readyState == 4 && this.status == 200) {
      myFunction(this);
    }
  };
  xmlhttp.open("GET", "HWR.xml", true);
  xmlhttp.send();
}
function myFunction(xml) {
  var i;
  var xmlDoc = xml.responseXML;
  var table="<tr><th>Artist</th><th>Title</th></tr>";
  var x = xmlDoc.getElementsByTagName("my:myFields");
  for (i = 0; i <x.length; i++) { 
    table += "<tr><td>" +
    x[i].getElementsByTagName("my:EmpName")[0].childNodes[0].nodeValue +
    "</td><td>" +
    x[i].getElementsByTagName("my:EmpTitle")[0].childNodes[0].nodeValue +
    "</td></tr>";
  }
  document.getElementById("demo").innerHTML = table;
}
</script>
Calv Reid
  • 15
  • 2

1 Answers1

0

You're dealing with HTTP, so the browser has no concept of a "folder" or what might be in it.

You would need to write a web service that would give you a list of URLs to loop over. Alternatively, you could write one which combined all the XML data into a single, larger document.

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335