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>
0

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.