0% found this document useful (0 votes)
16 views

DD 4

The document contains an XML file (lib.xml) that lists book loan records for a library with the book ID, ISBN, borrow date, and return date for 3 books. It also contains an HTML file (library.html) that uses JavaScript and XMLHttpRequest to retrieve the XML data and display it in a table on a web page with buttons to get the book details.

Uploaded by

sanjay yadav
Copyright
© © All Rights Reserved
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views

DD 4

The document contains an XML file (lib.xml) that lists book loan records for a library with the book ID, ISBN, borrow date, and return date for 3 books. It also contains an HTML file (library.html) that uses JavaScript and XMLHttpRequest to retrieve the XML data and display it in a table on a web page with buttons to get the book details.

Uploaded by

sanjay yadav
Copyright
© © All Rights Reserved
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
You are on page 1/ 3

lib.

xml
<?xml version='1.0' encoding="UTF-8"?>
<lib>
<row>
<ID>TCB54</ID>
<ISBN>MCC01</ISBN>
<BT_DATE>1998-02-21</BT_DATE>
<BR_DATE>1998-02-28</BR_DATE>
</row>
<row>
<ID>TCB54</ID>
<ISBN>SE01</ISBN>
<BT_DATE>1998-02-01</BT_DATE>
<BR_DATE>1998-02-08</BR_DATE>
</row>
<row>
<ID>TCB54</ID>
<ISBN>SPCC01</ISBN>
<BT_DATE>1998-02-21</BT_DATE>
<BR_DATE>1998-02-28</BR_DATE>
</row>
</lib>

library.html
<!DOCTYPE html>
<html>
<style>
table,th,td {

border : 1px solid black;


border-collapse: collapse;
}
th,td {
padding: 5px;
}
</style>
<body>

<button type="button" onclick="loadXMLDoc()">Get details</button>


<br><br>
<table id="demo"></table>

<script>
function loadXMLDoc() {
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
myFunction(xmlhttp);
}
};
xmlhttp.open("GET", "lib.xml", true);
xmlhttp.send();
}
function myFunction(xml) {
var i;
var xmlDoc = xml.responseXML;
var
table="<tr><th>ID</th><th>ISBN</th><th>BT_DATE</th><th>BR_DATE

</th></tr>";
var x = xmlDoc.getElementsByTagName("row");
for (i = 0; i <x.length; i++) {
table += "<tr><td>" +
x[i].getElementsByTagName("ID")[0].childNodes[0].nodeValue +
"</td><td>" +
x[i].getElementsByTagName("ISBN")[0].childNodes[0].nodeValue +
"</td><td>" +
x[i].getElementsByTagName("BT_DATE")[0].childNodes[0].nodeValue +
"</td><td>" +
x[i].getElementsByTagName("BR_DATE")[0].childNodes[0].nodeValue +
"</td></tr>";
}
document.getElementById("demo").innerHTML = table;
}
</script>

</body>
</html>

You might also like