See attached document for XML page Create your own XML file, with xml extension.
ID: 3698491 • Letter: S
Question
See attached document for XML page
Create your own XML file, with xml extension. There is no content restriction on XML file content, as long as it meets the syntax requirements of XML. At least three different tags at minimum and three layers from the root node should be created in this XML file's DOM tree Then create a website named "XML1" with two files: index.html and the above mentioned XML file using Visual Studio as demonstrated in last Monday class. The index.html should utilize typical AJAX programming procedure to (1) Establish HTTP connection to the XMLl website (2) Retrieve the XML file from XML1 website (3) Display all text of the XML file, but not any markup (i.e. tag) (4) Debug and test your site till every above function works and no error occurs. Use sample code at http://www.w3schools.com/xml/tryit.asp?filename try_dom xmlhttprequest as your reference. Through this lab you will become familiar with the typical AJAX programming approaches to access, display, and manipulate XML files on a web serverExplanation / Answer
function loadDoc() {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
myFunction(this);
}
};
xhttp.open("GET", "cd_catalog.xml", true);
xhttp.send();
}
function myFunction(xml) {
var i;
var xmlDoc = xml.responseXML;
var table="<tr><th>Title</th><th>Artist</th></tr>";
var x = xmlDoc.getElementsByTagName("CD");
for (i = 0; i <x.length; i++) {
table += "<tr><td>" +
x[i].getElementsByTagName("TITLE")[0].childNodes[0].nodeValue +
"</td><td>" +
x[i].getElementsByTagName("ARTIST")[0].childNodes[0].nodeValue +
"</td></tr>";
}
document.getElementById("demo").innerHTML = table;
}