Load XML object
Load XML object
Hi everyone, Im very newbie with jQuery, AJAX and I am trying to figure out how to load an XML object into a datatable.
I want to parse two news feeds from popular websites and then pass some of the information into the table. I am using a for loop to loop inside the feeds and then I have an XML object from which I would like to gather the information from. Here is what I have tried so far by searching on the forum:
```
$.ajax(feed[i], {
accepts:{
xml:"application/rss+xml"
},
dataType:"xml",
success:function(data) {
$(document).ready(function() {
$('#example').DataTable( {
"ajax": {
"dataType": "xml",
"url": feed[i],
"dataSrc" : function() {
}
},
retrieve: true,
columns: [
{ title: "some_info" },
{ title: "some_info" },
{ title: "some_info" },
{ title: "some_info" }
]
} );
} );
} );
```
Where feed is my array with the feeds and "data" is the xml object which I am trying to convert it into an acceptable type in order for the datatable to read it.
Thank you
Answers
What does
JSON.stringify(xmlToJson(data));
create? Can you show a dump of that array?Allan
Thanks for your answer Allan, actually it doesnt do anything because "xmlToJson" obviously gets undefined. I shouldnt include it,sorry. I have now edited it and deleted it.
It should be that the first parameter passed into the
ajax.dataSrc
option is the XML document as retrieved by$.ajax()
. You would then need to use some Javascript to convert that XML into an array of arrays or arrays of objects depending on how you want to use DataTables.Allan