Results 1 to 3 of 3
  1. #1
    sandy1000's Avatar
    sandy1000 is offline Member
    Join Date
    Dec 2010
    Posts
    11
    Rep Power
    0

    Smile read an xml file and display using jsp

    first prepare an xml file as defined below and name it as test.xml
    <?xml version="1.0" encoding="iso-8859-1"?>
    <CATALOG>
    <CD>
    <TITLE>Empire Burlesque</TITLE>
    <ARTIST>Bob Dylan</ARTIST>
    <COUNTRY>USA</COUNTRY>
    <COMPANY>Columbia</COMPANY>
    <PRICE>10.90</PRICE>
    <YEAR>1985</YEAR>
    </CD>
    <CD>
    <TITLE>Hide your heart</TITLE>
    <ARTIST>Bonnie Tyler</ARTIST>
    <COUNTRY>UK</COUNTRY>
    <COMPANY>CBS Records</COMPANY>
    <PRICE>9.90</PRICE>
    <YEAR>1988</YEAR>
    </CD>
    </CATALOG>


    Now prepare the jsp file as defined below as get_cd_catalog.jsp

    <html>
    <head>
    <script type="text/javascript">
    function loadXMLDoc()
    {
    if (window.XMLHttpRequest)
    {// code for IE7+, Firefox, Chrome, Opera, Safari
    xmlhttp=new XMLHttpRequest();
    }
    else
    {// code for IE6, IE5
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.onreadystatechange=function()
    {
    if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    xmlDoc=xmlhttp.responseXML;
    var txt="";
    x=xmlDoc.getElementsByTagName("TITLE");
    y=xmlDoc.getElementsByTagName("ARTIST");
    z=xmlDoc.getElementsByTagName("COUNTRY");

    alert(x);
    for (i=0;i<x.length;i++)
    {
    txt=txt + x[i].childNodes[0].nodeValue +" ";
    txt=txt + y[i].childNodes[0].nodeValue +" ";
    txt=txt + z[i].childNodes[0].nodeValue +"<br />";
    }
    document.getElementById("myDiv").innerHTML=txt;
    }
    }
    xmlhttp.open("GET","test.xml",true);
    xmlhttp.send();
    }
    </script>
    </head>

    <body>

    <h2>My CD Collection:</h2>
    <div id="myDiv"></div>
    <button type="button" onClick="loadXMLDoc()">Get my CD collection</button>

    </body>
    </html>

  2. #2
    gajendra1987 is offline Member
    Join Date
    Dec 2010
    Posts
    1
    Rep Power
    0

    Default

    Thats a good suggestion given by Sandy

  3. #3
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    10,476
    Rep Power
    16

    Default

    What does that have to do with Java?
    There's no Java, or JSP tags, in there at all are there?

Similar Threads

  1. Replies: 1
    Last Post: 12-01-2010, 06:35 PM
  2. how to read an image and display
    By santhosh_el in forum AWT / Swing
    Replies: 2
    Last Post: 04-04-2009, 12:43 PM
  3. Replies: 3
    Last Post: 01-29-2009, 10:20 AM
  4. Read-File Write Display substring
    By hiklior in forum New To Java
    Replies: 3
    Last Post: 04-18-2008, 11:45 AM
  5. Simplest way to read and display a jpeg image
    By Hasan in forum New To Java
    Replies: 1
    Last Post: 05-31-2007, 03:42 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •