Click here to Skip to main content
15,868,016 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi all
i have a URL displays XML data, and i want to take or read this data from this file and save it into data table or list using javascript.
i mean that all i want is how to read from XML file and save data into data table.

thanks
Posted
Comments
AmitGajjar 18-Nov-12 3:11am    
do you mean by database table ?
NNos2012 18-Nov-12 3:16am    
no , i want a way to read from XMl and display data in my page so, i need to make that a list or data table to store data first in it then display it.
AmitGajjar 19-Nov-12 1:43am    
See my solution.

Hi,

If you need to render your data in the html page form the javascript then why should you read the data through javascript and display ? you can use XSLT to transform your xml data into your desired design in html page.

Please refer http://www.w3schools.com/xsl/[^] link to know more about XSLT.

Let me know if helps you. Also see the example given in the above link

thanks
 
Share this answer
 
 
Share this answer
 
Comments
NNos2012 18-Nov-12 4:17am    
thanks alot for your help, but what about reading XML from URl
i mean that my XML data appears on html page like this


<user>

<name>abc
<class>xyz
<city>pqr

<info>
<id>123
456



and i don't want user to see it like this . i want to read it first and display it as i want and as you said before

thanks
AmitGajjar 19-Nov-12 1:44am    
yes, in that case XSLT helps you. you need to study it well.
Does this help ?
JavaScript
xmlhttp.open("GET", "employee.XML", false);
 xmlhttp.send(null); 
if (xmlhttp.status==200) 
{ xmlDoc = xmlhttp.responseXML; 
var empid= xmlDoc.getElementsByTagName("emp"); 
var total = placeMarks.length; 
var names = xmlDoc.getElementsByTagName("Name");
 var designation= xmlDoc.getElementsByTagName("designation"); 
var phone= xmlDoc.getElementsByTagName("phone"); ..... ; } 
else 
if (xmlhttp.status==404) { alert("XML could not be found"); 
}
 
Share this answer
 
Or you can use Jquery

JavaScript
$.get(url,function(data){
 xmlDoc = data; 
var empid= xmlDoc.getElementsByTagName("emp"); 
var total = placeMarks.length; 
var names = xmlDoc.getElementsByTagName("Name");
 var designation= xmlDoc.getElementsByTagName("designation");
 var phone= xmlDoc.getElementsByTagName("phone"); });
 
Share this answer
 
Comments
Nelek 18-Nov-12 5:29am    
Please don't post solutions to add information, to ask something or to comment another user.
- To add information to your message, you can use the widget "Improve question" / "Improve solution" at the bottom of your text.
- To ask/answer a user, you can use the widget "Have a question or comment?" (as I am doing right now with you) or the widget "reply" in another comment.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900