Start networking and exchanging professional insights

Register now or log in to join your professional community.

Follow

How To connect XML database to any HTML File Table or to some inputs like checkboxes with javascript or jquery , please write the function to do that?

please show me what your function elements mean ?

 

can I use Google Drive or Dropbox to share that XML file and connect it to any HTML file at any place or web server ?

user-image
Question added by Deleted user
Date Posted: 2015/07/16

You can do that by creating XMLHttpRequest Object, first make an xml file and define your tags or data. 

Then use the following code in javascript to make a call to the server

xmlhttp=new XMLHttpRequest(); //XMLHttpRequest Object

xmlhttp.open("GET","XML_FILE_NAME",false);  //Replace your xml filename at this line

xmlhttp.send();

xmlDoc=xmlhttp.responseXML;

 

Once you get the data you can use document.write() function to create table and loops to display them inside the table like this:

 

document.write("<table><tr><th>TABLE_HEAD_1</th> <th>TABLE_HEAD_2</th></tr>");

var x=xmlDoc.getElementsByTagName("TAG_NAME");

for (i=0;i<x.length;i++)   {  

//YOUR CODE TO DISPLAY CHILD NODES OF THE TAG DEFINED IN XML FILE

}

document.write("</table>");

Yes you can use your xml as database but you will need an ajax and/or http call through JS, here is an example:

<table id="demo"></table><script>function loadXMLDoc() {  var xmlhttp = new XMLHttpRequest();  xmlhttp.onreadystatechange = function() {    if (xmlhttp.readyState ==4 && xmlhttp.status ==) {      myFunction(xmlhttp);    }  }  xmlhttp.open("GET", "YOUR_XML_URL", true);  xmlhttp.send();}function myFunction(xml) {  var i;  var xmlDoc = xml.responseXML;  var table="<tr><th>Artist</th><th>Title</th></tr>";  var x = xmlDoc.getElementsByTagName("CD");  for (i =0; i <x.length; i++) {     table += "<tr><td>" +    x[i].getElementsByTagName("ARTIST")[0].childNodes[0].nodeValue +    "</td><td>" +    x[i].getElementsByTagName("TITLE")[0].childNodes[0].nodeValue +    "</td></tr>";  }  document.getElementById("demo").innerHTML = table;}</script>

 

More Questions Like This

Do you need help in adding the right keywords to your CV? Let our CV writing experts help you.