XML data into table



I've been attempting the past week or so to parse XML data from a public API into a table cell, and have yet to find anything that's working due to the XML loading time (~100-500ms) when the function is loaded through a button click. The reason I'm using a public API instead of a local .xml file, is because I want the prices to be self-updating.


The URL here in question is http://ift.tt/1fNsC3K which returns the XML result (can be changed to a JSON result by changing to /marketstat/json?)



<?xml version='1.0' encoding='utf-8'?>
<evec_api version="2.0" method="marketstat_xml">
<marketstat><type id="34">
<buy><volume>18280008457</volume><avg>5.41</avg><max>5.99</max><min>3.12</min><stddev>0.57</stddev><median>5.59</median><percentile>5.86</percentile></buy>
<sell><volume>17971535059</volume><avg>6.38</avg><max>14.99</max><min>5.90</min><stddev>1.69</stddev><median>6.20</median><percentile>6.05</percentile></sell>
<all><volume>36660543516</volume><avg>5.83</avg><max>14.99</max><min>0.20</min><stddev>1.74</stddev><median>5.90</median><percentile>3.72</percentile></all>
</type></marketstat>
</evec_api>


Now, the data I want from this one is the Sell:Min, but can't seem to find a way that wont return Null


I've tried different things between JavaScript and JSON



// create script element
var script = document.createElement('script');
// assing src with callback name
script.src = 'http://ift.tt/1E7LcFn'+RegID;
// insert script to document and load content
document.body.appendChild(script).childNodes[0];
console.log("Script is "+script);
}
function insertReply(content) {
document.getElementById('testing').innerHTML = content;

}


and



var jqxhr = $.getJSON( "http://ift.tt/1EZa0wu", function() {
console.log( "success" );
})
.done(function() {
console.log( "second success" );
})
.fail(function() {
console.log( "error" );
})
.always(function() {
console.log( "complete" );
});
console.log("Price for 34 is "+jqxhr.sell.forQuery.min);
$(jqxhr).ready(function() {
console.log("Price for 34 is "+jqxhr.sell.forQuery.min);
// put all your jQuery goodness in here.
});
// Perform other work here ...
// Set another completion function for the request above
jqxhr.complete(function() {
console.log( "second complete" );
});


I would like to note though, that I haven't really worked much with JavaScript, and this is my first attempt at parsing data.


Thanks in advance :)


No comments:

Post a Comment