Simple representation for dumping and showing data into html from a xml file


/ Published in: XML
Save to your folder(s)



Copy this code and paste it in your HTML
  1. <!--<Developer by shashikanth reddy>-->
  2. <!--<Logic borrowed from other sources through small snippets, and i hgave customized to simple presentation>-->
  3. <html>
  4. <body>
  5.  
  6. <script type="text/javascript">
  7. if (window.XMLHttpRequest)
  8. {// code for IE7+, Firefox, Chrome, Opera, Safari
  9. xmlhttp=new XMLHttpRequest();
  10. }
  11. else
  12. {// code for IE6, IE5
  13. xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  14. }
  15. xmlhttp.open("GET","targetpage.xml",false);
  16. xmlhttp.send();
  17. xmlDoc=xmlhttp.responseXML;
  18.  
  19. document.write("<table border='1' cellpadding='4' cellspacing='4' align='center' frame='box' rules='none' border='1'>");
  20. var x=xmlDoc.getElementsByTagName("employee");
  21. //alert(x.length);
  22. document.write("<td align='center'>Name</td>");
  23. document.write("<td align='center'>Designation</td>");
  24. document.write("<td align='center'>Department</td>");
  25. document.write("<td align='center'>Current Location</td>");
  26. document.write("<td align='center'>Company</td>");
  27. document.write("<td align='center'>Address</td>");
  28. document.write("</td></tr>");
  29. for (i=0;i<x.length;i++)
  30. {
  31. document.write("<tr><td align='center'>");
  32. document.write(x[i].getElementsByTagName("name")[0].childNodes[0].nodeValue);
  33. document.write("</td><td align='center'>");
  34. document.write(x[i].getElementsByTagName("desig")[0].childNodes[0].nodeValue);
  35. document.write("</td><td align='center'>");
  36. document.write(x[i].getElementsByTagName("dept")[0].childNodes[0].nodeValue);
  37. document.write("</td><td align='center'>");
  38. document.write(x[i].getElementsByTagName("currentloc")[0].childNodes[0].nodeValue);
  39. document.write("</td><td align='center'>");
  40. document.write(x[i].getElementsByTagName("company")[0].childNodes[0].nodeValue);
  41. document.write("</td><td align='center'>");
  42. document.write(x[i].getElementsByTagName("address")[0].childNodes[0].nodeValue);
  43. document.write("</td></tr>");
  44. }
  45. document.write("</table>");
  46. </script>
  47.  
  48. </body>
  49. </html>
  50.  
  51. --------------****************---------------
  52.  
  53.  
  54. <!--xml file targetpage targetpage.php -->
  55.  
  56.  
  57. <?xml version="1.0" encoding="iso-8859-1"?>
  58. <shashi>
  59. <employee>
  60. <name>Syed Abdul baqi</name>
  61. <desig>SSE</desig>
  62. <dept>PHP</dept>
  63. <currentloc>Dubai</currentloc>
  64. <company>Bodhtree</company>
  65. <address>Malakpet</address>
  66. </employee>
  67.  
  68. <employee>
  69. <name>Shashikanth reddy</name>
  70. <desig>JSE</desig>
  71. <dept>PHP</dept>
  72. <currentloc>Hyderabad</currentloc>
  73. <company>Self</company>
  74. <address>Dilsukhnagar</address>
  75. </employee>
  76.  
  77. <employee>
  78. <name>Raman</name>
  79. <desig>SSE</desig>
  80. <dept>Websphere</dept>
  81. <currentloc>Madurai</currentloc>
  82. <company>Honeywell</company>
  83. <address>Habsiguda</address>
  84. </employee>
  85.  
  86. <employee>
  87. <name>Sridhar</name>
  88. <desig>SSE</desig>
  89. <dept>PHP</dept>
  90. <currentloc>Hyderabad</currentloc>
  91. <company>Votive</company>
  92. <address>Bhel</address>
  93. </employee>
  94. </shashi>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.