- First you need to do a AJAX call to fetch the data from your xml file.
- Second inside your success method you will receive the XML data, you need to parse this data using $.parseXML() and then convert it into a jquery object using
$(yourXML)
after that its simple as working on your DOM objects.
- You can read the attribute using the
.attr()
function.
Below is the example code, (here is a fiddle which demonstrates working with xml data in jquery)
$(function(){ // alternate syntax for $(document).ready(function(){..
$.ajax({
type: "GET" ,
url: "http://xxxxxx/y.xml" ,
dataType: "xml" , // make sure to set the dataType to xml
success: function(xml) {
var xmlDoc = $.parseXML(xml); //Parse the givn XML
var $xml = $(xmlDoc); // convert XML into jquery object
var creationDate = $xml.find("ris-metadata").attr('creation');
alert(creationDate); // this will give you the required data.
// this will update the second column data of the first row.
$('#yourTableId tbody td:eq(1)').text(creationDate);
}
});
});