Indhu Mathi

Indhu Mathi

  • NA
  • 60
  • 6.5k

I need to pull a xml data into html table using jquery.

Jun 29 2017 7:48 AM
employee.xml 
<?xml version="1.0" encoding="utf-8" ?>
<employeedetails>
<Employee>
<Name>"Indhu"</Name>
<ID>"571367"</ID>
<Designation>"Programmer Analyst"</Designation>
</Employee>
<Employee>
<Name>"Swetha"</Name>
<ID>"568877"</ID>
<Designation>"Analyst"</Designation>
</Employee>
<Employee>
<Name>"Vibisha"</Name>
<ID>"568879"</ID>
<Designation>"Senior Analyst"</Designation>
</Employee>
</employeedetails>
 
script_tbemployeedetails.js
$(document).ready(function(){
$.ajax({
type:'GET',
url:'employee.xml',
dataType:'xml',
success:function(xmlData){
$("Employee",xmlData).each(function(){
String name=$(this).find("Name").text(),
String id=$(this).find("ID").text(),
String designation=$(this).find("Designation").text();
$(tb_employee).append('<tr>');
$(tb_employee).append('<td>'+name+'</td>');
$(tb_employee).append('<td>'+id+'</td>');
$(tb_employee).append('<td>'+designation+'</td>');
$(tb_employee).append('<tr>');
});
)}
});
}
defaut.aspx 
 
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="EmployeeDetails_XML._Default" %>
<!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>
<title>Extract and Read XML Data Using jQuery and Ajax</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js"></script>
</head>
<body>
<form id="form1" runat="server">
<div>
<table id="tb_employee">
<tr>
<th>NAME</th>
<th>ID</th>
<th>DESIGNATION</th>
</tr>
</table>
</div>
<asp:XmlDataSource ID="XmlDataSource1" runat="server" DataFile="~/employee.xml">
</asp:XmlDataSource>
</form>
</body>
</html>
 
 This is my code.I could not pull xml data into html table
 Can anyone help to do this
 
 
 
 

Answers (3)