Results 1 to 3 of 3
- 12-30-2010, 10:55 AM #1
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>
- 12-31-2010, 07:11 AM #2
Member
- Join Date
- Dec 2010
- Posts
- 1
- Rep Power
- 0
Thats a good suggestion given by Sandy
- 01-04-2011, 11:50 AM #3
Moderator
- Join Date
- Apr 2009
- Posts
- 10,476
- Rep Power
- 16
Similar Threads
-
Display only certain contents of text file and edit display
By blkshrk81 in forum New To JavaReplies: 1Last Post: 12-01-2010, 06:35 PM -
how to read an image and display
By santhosh_el in forum AWT / SwingReplies: 2Last Post: 04-04-2009, 12:43 PM -
How can I call my database read method to display its ArrayList?
By matpj in forum New To JavaReplies: 3Last Post: 01-29-2009, 10:20 AM -
Read-File Write Display substring
By hiklior in forum New To JavaReplies: 3Last Post: 04-18-2008, 11:45 AM -
Simplest way to read and display a jpeg image
By Hasan in forum New To JavaReplies: 1Last Post: 05-31-2007, 03:42 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks