Copy the XML file books.xml at http://www.w3schools.com/xml/dom_nodes_set.asp an
ID: 3936377 • Letter: C
Question
Copy the XML file books.xml at http://www.w3schools.com/xml/dom_nodes_set.asp and create a website (i.e. Webserver) using WebMatrix. Along with the XML file, coding is concentrated in the primary HTML file (the initial name is "index.html") of this website. In the HTML file, write JavaScript code that Client sends a XML HTTP request to this Webserver, successfully receives the replied XML file, i.e. books.xml, and generates its XML DOM. Display the original values of elements of all books in the XML DOM on the HTML DOM of the HTML file. Dynamically change the XML DOM such that every book's publishing year, i.e. element, is shifted 10 years earlier. A loop control structure must be used in order to adapt the change in book number of the book store without revision of the JavaScript code inside this HTML file. Display the updated prices of all books in the XML DOM on the HTML DOM of the HTML file.Explanation / Answer
HTML CODE:
<!DOCTYPE html>
<html>
<body>
<p id="demo"></p>
<script>
var xhttp; // generating http XML request
xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
display(this);
}
};
xhttp.open("GET", "books.xml", true);
xhttp.send();
function display(xml) {
var x, i, yr1, yr2,xmlDoc;
xmlDoc = xml.responseXML;
yr1 = "";
yr2 = "";
x = xmlDoc.getElementsByTagName("year");
for (i = 0; i < x.length; i++) {
var value = 0;
value = parseInt(x[i].childNodes[0].nodeValue);
yr1 += value + "<br>";
value = value + 10;
yr2 += value + "<br>";
}
document.getElementById("demo").innerHTML = "Original Years<br>" yr1+ "<br>Manipulated Years" + yr2;
}
</script>
</body>
</html>
OUTPUT:
Original Years
2005
2005
2003
2003
Manipulated Years
2015
2015
2013
2013
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.