// Promisify parse XML async function parse(file) { const promise = await new Promise((resolve, reject) => { const parser = new xml2js.Parser({ explicitArray: false }); parser.parseString(file, (error, result) => { if (error) reject(error); else resolve(result); }); }); return promise; }
constructor() { this.parser = new xml2js.Parser() }
program.arguments('<file>').action(function (file) { var xmlParser = new xml2js.Parser(); function setupDict() { return new Promise(function (resolve, reject) { fs.readFile(file, function (err, rawData) { if (err) { log(err); process.exit(1); } var data = escape(rawData.toString(), XML_IGNORE); xmlParser.parseString(data, function (parseError, obj) { if (parseError) reject(parseError);else resolve(obj.JMdict.entry); }); }); }); } var outputFilename = "".concat(file, ".json"); setupDict().then(function (dictionary) { fs.writeFileSync(outputFilename, JSON.stringify(dictionary), 'utf8'); }); });
function doParseForName(conn, data, cb) { var parser = new xml2js.Parser(); parser.parseString(data, function (e, result){ if (e) return cb(e); if (result.SharedFlowBundle) { if (conn.verbosity>0) { utility.logWrite(sprintf('found name: %s', result.SharedFlowBundle.$.name)); } return cb(null, result.SharedFlowBundle.$.name); } if (result.APIProxy) { if (conn.verbosity>0) { utility.logWrite(sprintf('found name: %s', result.APIProxy.$.name)); } return cb(null, result.APIProxy.$.name); } cb({error:'cannot determine asset name'}); }); }
function processResponseType (res, responseString, callback) { //debug('res %o ', res); //debug('res.headers %o ', res.headers); if (RESPONSE_CONTENT_TYPE.indexOf(res.headers[ 'content-type' ].toLowerCase()) > -1) { debug('It is XML Response'); var parser = new xml2js.Parser({ explicitArray: false, ignoreAttrs: true }); parser.parseString(responseString, function (err, response) { //debug('response after parsing JSON %o ', response); return callback(null, response); }); } else { debug('It is NON-XML Response'); try { var response = JSON.parse(responseString); return callback(null, response); } catch (exception) { debug('exception ', exception); return callback(callback, responseString); } } }
let validationError; let parser = new xml2js.Parser({ validator: this._validateXml });
response.on('end', function () { var parser = new xml2js.Parser(); parser.parseString(str, function (err, result) { packet = { edge: { ip: configuration.edge_address, uptime: result.rtmp.uptime[0], accepted: result.rtmp.naccepted[0], bandwidth_in: result.rtmp.bw_in[0], total_traffic_in: result.rtmp.bytes_in[0], bandwidth_out: result.rtmp.bw_out[0], total_traffic_out: result.rtmp.bytes_out[0], clients: result.rtmp.server[0].application[0].live[0].nclients[0] }, security: { key: configuration.load_balancer_key } }; //send update packet containing the edge object ioClient.emit('sendserver', packet); }); } ) ;
var parser = new xml2js.Parser({explicitArray: false}); parser.parseString(res_body, function (err, result) { if (!err) {
http({ url }, (error, response) => { if (!error && response.statusCode === 200) { const body = response.body const parser = new xml2js.Parser() parser.parseString(body, (err, result) => { if (!err) {
this._parser = new xml2js.Parser();
var parser = new xml2js.Parser({explicitArray: false}); parser.parseString(res_body, function (err, result) { if (!err) {
function processResponseType (res, responseString, callback) { var xmlParser = new xml2js.Parser({ mergeAttrs: true, explicitArray: false,
function parseXML(xml) { const parser = new xml2js.Parser({ // explicitArray: false }); return new Promise((resolve, reject) => { parser.parseString(xml, (err, result) => { if (err) { return reject(err); } resolve(result); }); }); }
program .arguments('<file>') .action((file) => { const xmlParser = new xml2js.Parser(); function setupDict() { return new Promise((resolve, reject) => { fs.readFile(file, (err, rawData) => { if (err) { log(err); process.exit(1); } const data = escape(rawData.toString(), XML_IGNORE); xmlParser.parseString(data, (parseError, obj) => { if (parseError) reject(parseError); else resolve(obj.JMdict.entry); }); }); }); } const outputFilename = `${file}.json`; setupDict().then((dictionary) => { fs.writeFileSync(outputFilename, JSON.stringify(dictionary), 'utf8'); }); });
let validationError; let parser = new xml2js.Parser({ validator: this._validateXml });