self.fetchContent(URL, function (err, content) { if (err) { return callback(err, null); } // Parse the content fetch from european central bank var xmlObj = self.parseContent(content); var rootCube = xmlObj.childNamed("Cube"); var cube = rootCube.childNamed("Cube"); if (cube === null || _.isUndefined(cube) || _.isUndefined(cube.attr)) { return callback(new UnsupportedCurrencyPairException(currencyPair, Provider), null); } // search for quote currency rate var rateElement = cube.childWithAttribute('currency', currencyPair.getQuoteCurrency()); // return error if rate is not available if (rateElement === null || _.isUndefined(rateElement) || _.isUndefined(rateElement.attr) || _.isUndefined( rateElement.attr.rate)) { return callback(new UnsupportedCurrencyPairException(currencyPair, Provider), null); } var date = cube.attr.time ? new Date(cube.attr.time) : new Date(); return callback(null, new Rate(rateElement.attr.rate, date, Provider)); });