How can I read and sign XML data (array of different sizes) using jQuery?
AJAX to read line node from XML and store in javascript array, in XML array size is not constant.
My Code:
$(document).ready(function(){
$.ajax({
type: "GET",
url: "sites.xml",
dataType: "xml",
success: function(xml) {
$(xml).find('msg').each(function() {
var title = $(this).find('title').text();
i = 0;
tic = new Array();
$(this).find('desc').each(function() {
tic.push($(this).find('line').text());
alert(tic[i]);
i++;
});
});
}
});
});
and XML File (Demo)
<msgs>
<msg>
<title>ABC</title>
<desc>
<line>test 1</line>
<line>test 2</line>
<line>test 2</line>
</desc>
<time>5</time>
</msg>
</msgs>
Can Someone help me out please
To read in all of the
lineelements into an array changeto
This will process each
lineelement and add it to your array and then place your array initialisation at the topvar tic = [];… so complete success function would look like this :Working example here