Html table with external xml | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Html table with external xml

Please help me to create an html table with external xml data. There will be an html file as index.html and an xml file as data.xml that contains all data of the table. Please help me my friend. I am new to this.

14th Jul 2019, 7:31 PM
FAHEEM ARSALAN
FAHEEM ARSALAN - avatar
15 Answers
0
You can either use CDATA in XML, or you could embed the XML inside the html-file, inside a <script>-tag, as such: <script id="xml-table" type="text/xmldata"> //Your code here </script> Then use the javascript DOM to get the XML-script.
14th Jul 2019, 7:43 PM
Roolin
Roolin - avatar
0
Would you please help me by a source code of this tiny project. Please sir help me.
14th Jul 2019, 7:49 PM
FAHEEM ARSALAN
FAHEEM ARSALAN - avatar
14th Jul 2019, 8:06 PM
Roolin
Roolin - avatar
0
I just want an html file and an xml file please hlelp me..
14th Jul 2019, 8:10 PM
FAHEEM ARSALAN
FAHEEM ARSALAN - avatar
0
Is it necessary to have two files or could you have ony a single file? With CDATA you could put the xml data into html-tags, and even style the elements with css
14th Jul 2019, 8:15 PM
Roolin
Roolin - avatar
0
No they will be just different file one of them will be index.html and another will be data.xml Thanks
14th Jul 2019, 8:20 PM
FAHEEM ARSALAN
FAHEEM ARSALAN - avatar
0
No they will be just different file one of them will be index.html and another will be data.xml Thanks
14th Jul 2019, 8:20 PM
FAHEEM ARSALAN
FAHEEM ARSALAN - avatar
0
Hello my friend are you online?
14th Jul 2019, 8:36 PM
FAHEEM ARSALAN
FAHEEM ARSALAN - avatar
0
Hello my friend are you online?
14th Jul 2019, 8:36 PM
FAHEEM ARSALAN
FAHEEM ARSALAN - avatar
0
The following code retrieves tags from a "data-xml"-file. You will need to change the "getelementsbytagname" to the corresponding xml-tags that you have, and you have to call the "loadXML"-function in order for the data to be retrieved. I hope this helped :) Paste this at the bottom of the body-tag in your index.html: <script> function loadXML(){ var xmlHttp = new XMLHttpRequest(); xmlHttp.onreadystatechange = function() { if(this.readyState == 4 && this.status == 200) { getdata(this); } } xmlHttp.open('GET', 'data.xml', true); xmlHttp.send(); } function getdata(xml){ var x, i, xmlDoc, table; xmlDoc = xml.responseXML; table = '<tr><th>Artist</th><th>Title</th></tr>'; 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>
14th Jul 2019, 8:36 PM
Roolin
Roolin - avatar
0
Hey my friend are you real in your photo?
14th Jul 2019, 8:40 PM
FAHEEM ARSALAN
FAHEEM ARSALAN - avatar
0
No, the man in my profile picture is a guy named Harold, not me lol
14th Jul 2019, 8:41 PM
Roolin
Roolin - avatar
0
So who are you man? 😸😸
14th Jul 2019, 8:42 PM
FAHEEM ARSALAN
FAHEEM ARSALAN - avatar
0
Why we can not be a good friend?
14th Jul 2019, 8:44 PM
FAHEEM ARSALAN
FAHEEM ARSALAN - avatar
0
🙀🙀🙀
14th Jul 2019, 8:44 PM
FAHEEM ARSALAN
FAHEEM ARSALAN - avatar