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.
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.
0
Would you please help me by a source code of this tiny project. Please sir help me.
0
This might be of help: https://www.w3schools.com/xml/ajax_applications.asp
0
I just want an html file and an xml file please hlelp me..
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
0
No they will be just different file one of them will be index.html and another will be data.xml
Thanks
0
No they will be just different file one of them will be index.html and another will be data.xml
Thanks
0
Hello my friend are you online?
0
Hello my friend are you online?
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>
0
Hey my friend are you real in your photo?
0
No, the man in my profile picture is a guy named Harold, not me lol
0
So who are you man? 😸😸
0
Why we can not be a good friend?
0
🙀🙀🙀