convertXMLStringToJson(xmlString) { //Converte o XLM para Json return JSON.parse(convert.xml2json(xmlString, { compact: true })); }
this._ssdpClient.on('response', (headers, statusCode, rinfo) => { if (statusCode === 200 && headers.ST === URN_IGD) { const req = HTTP.request(headers.LOCATION, { method: 'GET' }, (res) => { let xml = ''; res.on('data', (chunk) => { xml += chunk.toString(); }); res.on('end', () => { const json = JSON.parse(XMLJS.xml2json(xml, { compact: true })); for (let device = json && json.root && json.root.device && json.root.device; device; device = device.deviceList && device.deviceList.device) { const service = device.serviceList && device.serviceList.service; if (service && service.serviceType && service.serviceType._text == URN_WAN) { this._gwLocation = headers.LOCATION; this._WANIPConnectionURL = new URL(service.controlURL._text, headers.LOCATION); this._startProxy(); break; } } }); }); req.end(); } });
/** * Returns an array of News objects for the given symbol. * @author Torrey Leonard <https://github.com/Ladinn> * @param {String} symbol * @returns {Promise<Array>} */ static getFromYahoo(symbol) { return new Promise((resolve, reject) => { request({ uri: 'http://feeds.finance.yahoo.com/rss/2.0/headline?s=' + symbol + '®ion=US&lang=en-US' }, (error, response, body) => { if (error) reject(error); else if (response.statusCode !== 200) reject(new LibraryError(body)); else { const result = JSON.parse(xmlJS.xml2json(body, {compact: true, spaces: 0})).rss.channel.item; let array = []; result.forEach(o => { array.push(new News({ title: o.title._text, description: o.description._text, date: new Date(o.pubDate._text), url: o.link._text })) }); resolve(array); } }) }) }