NEWS: Total Picture Views: 151536 | Total Article Views: 161050 | Top 5 Most Popular Article: 1. Am I Stuck Algorithm with Becker Robot | 2. PickUpThings with Becker Robot | 3. How to read a JSON and work with it | 4. Encrypted Data GUI (Download .Zip) | 5. Create Wall and Things with Becker

Display XML information into a Table 2 Javascript


In this example I will show you how to display a xml structure information into a table in Javascript.


<!DOCTYPE html>
<head lang="en">
    <meta charset="UTF-8">
    <title>In-Class Exercise 2</title>

    <script type="text/javascript">
        function readXML() {
            var xml = document.getElementById("myXML");
            var emp = xml.getElementsByTagName("Employee");

            document.write('<table border="1">');
            document.write("<tr><th>Employee ID</th><th>Employee First Name</th><th>Employee Last Name</th><th>Employee DOB</th><th>Employee Department</th></tr>")
            for (var i = 0; i <= emp.length; i++) {
                var id = emp[i].getElementsByTagName("Emp_Id")[0];

                var fname = emp[i].getElementsByTagName("Emp_Name")[0].getElementsByTagName("First")[0];
                var lname = emp[i].getElementsByTagName("Emp_Name")[0].getElementsByTagName("Last")[0];

                var month = emp[i].getElementsByTagName("Emp_DOB")[0].getElementsByTagName("Month")[0];
                var day = emp[i].getElementsByTagName("Emp_DOB")[0].getElementsByTagName("Day")[0];
                var year = emp[i].getElementsByTagName("Emp_DOB")[0].getElementsByTagName("Year")[0];

                var dept = emp[i].getElementsByTagName("Emp_Dept")[0];

                document.write("<tr><td>" + id + "</td>");
                document.write("<td>" + fname + "</td>");
                document.write("<td>" + lname + "</td>");
                document.write("<td>" + day + "/" + month + "/" + year + "</td>");
                document.write("<td>" + dept + "</td>");

    <xml id="myXML" style="display:none">


                <Emp_Dept>Human resource</Emp_Dept>


    <button onclick="readXML();">Click on me!</button>
Attachments: None

Tags: Table XML

Total Views: 866

My name is Jean-Mathieu

I created this website so other people could enjoy finding useful stuff easier. If you have any question do not hesitate to contact me.

jean8mathieuCreated on 02/23/15


Disclosure: We are a website that needs compensation to operate like any other website on the internet.
We may receive consideration for our reviews but we are totally unbiased and do not accept paid reviews or fake reviews claiming to be something they are not.