i'm trying to get some tags from the next xml file which is located here: http://open.api.ebay.com/shopping?version=581&appid=EBAYU91VTR1SQ8H917BC11O3BW8U4J&action=getResults&callname=FindItemsAdvanced&QueryKeywords=Aston+Martin+V12+Vanquish&categoryId=220
what do i need to do in order to get the "110" from the tags below:
<TotalItems>110</TotalItems>
using javascript?
Best How To :
Here is a basic example, it uses YQL to bypass CORS
var pre = document.getElementById('out'),
oReq = new XMLHttpRequest(),
url = 'http://open.api.ebay.com/shopping?version=581&appid=EBAYU91VTR1SQ8H917BC11O3BW8U4J&action=getResults&callname=FindItemsAdvanced&QueryKeywords=Aston+Martin+V12+Vanquish&categoryId=220',
yql = 'http://query.yahooapis.com/v1/public/yql?q=' + encodeURIComponent('select * from xml where url="' + url + '"') + '&format=xml&callback';
function updateProgress(oEvent) {
if (oEvent.lengthComputable) {
pre.textContent = oEvent.loaded / oEvent.total;
} else {
pre.textContent = 'Unable to compute progress information since the total size is unknown.';
}
}
function transferComplete(evt) {
pre.textContent = 'The transfer is complete.';
var doc = new DOMParser().parseFromString(evt.target.responseText, "application/xml"),
firstTotalItems = doc.getElementsByTagName('TotalItems')[0];
pre.textContent += '\nTotalItems: ' + firstTotalItems.textContent;
}
function transferFailed(evt) {
status.textContent = 'An error occurred while transferring the file.';
}
function transferCanceled(evt) {
status.textContent = 'The transfer has been canceled by the user.';
}
oReq.addEventListener("progress", updateProgress, false);
oReq.addEventListener("load", transferComplete, false);
oReq.addEventListener("error", transferFailed, false);
oReq.addEventListener("abort", transferCanceled, false);
oReq.open("GET", yql, true);
oReq.send(null);
<pre id="out"></pre>