Page

How To Treverse Data In xml file Using Java Script

//Book.html



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script language="javascript1.2">
    function loadXMLDoc(filename)
    {
        if (window.XMLHttpRequest)
          {
          xhttp=new XMLHttpRequest();
          }
        else // code for IE5 and IE6
          {
          xhttp=new ActiveXObject("Microsoft.XMLHTTP");
          }
        xhttp.open("GET",filename,false);
        xhttp.send();
        return xhttp.responseXML;
    }
  
    xmlDoc=loadXMLDoc("Library.xml");

    x=xmlDoc.getElementsByTagName("BOOKID");
    alert("Code Working");
  
  
    for (i=0;i<x.length;i++)
    {
      
      document.write(x[i].childNodes[5].childNodes[0].nodeValue);
      document.write("<br>");
    
    }
  
  
</script>>

</head>

<body>
</body>
</html>

//Library.xml

<?xml version="1.0" encoding="iso-8859-1"?>

<LIBRARY>
<BOOKID>
<BOOKTITLE>Operating system</BOOKTITLE>
<BOOKNAME>Windows xp</BOOKNAME>
<BOOKAUTHOR>Aasim</BOOKAUTHOR>
<BOOKPUBLISHER>Ram Publication</BOOKPUBLISHER>
<PUBLICATIONYEAR>1999</PUBLICATIONYEAR>
<BOOKPRICE>500</BOOKPRICE>
<BOOKLOGO>
<SOURCE>LPU Library</SOURCE>
<HEIGHT>20</HEIGHT>
<WEIGHT>10</WEIGHT>
</BOOKLOGO>
<BOOKSECTION>001</BOOKSECTION>
<BOOKTYPE>CSE</BOOKTYPE>
<BOOKEDITION>2000</BOOKEDITION>
</BOOKID>

<BOOKID>
<BOOKTITLE>Operating system</BOOKTITLE>
<BOOKNAME>Windows 7</BOOKNAME>
<BOOKAUTHOR>Ram</BOOKAUTHOR>
<BOOKPUBLISHER>Ram Publication</BOOKPUBLISHER>
<PUBLICATIONYEAR>2000</PUBLICATIONYEAR>
<BOOKPRICE>400</BOOKPRICE>
<BOOKLOGO>
<SOURCE>LPU Library</SOURCE>
<HEIGHT>10</HEIGHT>
<WEIGHT>16</WEIGHT>
</BOOKLOGO>
<BOOKSECTION>002</BOOKSECTION>
<BOOKTYPE>CSE</BOOKTYPE>
<BOOKEDITION>2010</BOOKEDITION>
</BOOKID>


<BOOKID>
<BOOKTITLE>Operating system</BOOKTITLE>
<BOOKNAME>Windows 8</BOOKNAME>
<BOOKAUTHOR>Aasim</BOOKAUTHOR>
<BOOKPUBLISHER>Ram Publication</BOOKPUBLISHER>
<PUBLICATIONYEAR>1999</PUBLICATIONYEAR>
<BOOKPRICE>500</BOOKPRICE>
<BOOKLOGO>
<SOURCE>LPU Library</SOURCE>
<HEIGHT>20</HEIGHT>
<WEIGHT>10</WEIGHT>
</BOOKLOGO>
<BOOKSECTION>003</BOOKSECTION>
<BOOKTYPE>CSE</BOOKTYPE>
<BOOKEDITION>2000</BOOKEDITION>
</BOOKID>

</LIBRARY>

No comments:

Post a Comment