How to use the xml2js.Parser function in xml2js

To help you get started, we’ve selected a few xml2js examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github axlemax / sfdx / cmd / deployFlows.js View on Github external
errorMsg += '\n' + fileError
      if (!argv.quiet) console.error(fileError)
      return { stderr: errorMsg }
    }
  } else {
    // No flow directory
    return {}
  }

  const flowDefs = []
  const regexDefFilename = /.+(?=\.flowDefinition-meta\.xml)/
  for (const defFile of defFileList) {
    const defFilename = regexDefFilename.exec(defFile)[0]

    // Get active version number from definition files
    const parser = new xml2js.Parser()
    const fileData = await fs.readFileSync(joinPath(defPath, defFile))
    parser.parseString(fileData, (err, result) => {
      const defVersion = parseInt(result['FlowDefinition']['activeVersionNumber'])
      flowDefs[defFilename] = { activeVersion: defVersion }
    })
  }

  // For the filename, look at everything until '-' followed by a number
  const regexFlowFilename = /.+?(?=-[0-9]+\.)/

  let flowFile = ''
  let flowsToKeep = config.inactiveFlowsToKeep

  if (isNaN(flowsToKeep)) {
    console.error(err('Invalid number of flows specified in configuration.'))
    process.exit(1)
github Trevelopment / MZD-AIO / app / assets / js / messages-settings.js View on Github external
/* jshint esversion:6, -W117, -W116 */
var xml2js = require('xml2js')
// var settingsData = new Config({ 'name': 'msgSettings' })
var data2edit, msgLangs = [],
  currLangMsgs = []
var currMsgLang
var parser = new xml2js.Parser()

function getMsgLangs () {
  var messageFile = (fs.existsSync(`${varDir}/message_replies/jci/settings/configurations/blm_msg-system.xml`) ? `${varDir}` : `${builddir}/config`)
  messageFile += `/message_replies/jci/settings/configurations/blm_msg-system.xml`
  fs.readFile(path.resolve(messageFile), function (err, data) {
    if (err) console.log(err)
    parser.parseString(data, function (err, result) {
      if (err) console.log(err)
      if (data2edit !== result) {
        data2edit = result
        //   console.dir(data2edit.Node.Node[0].Node[0].$.key)
        for (var x in data2edit.Node.Node[0].Node) msgLangs.push(data2edit.Node.Node[0].Node[x].$.key)
        // getMsgsForLang(msgLangs[currentMsgLang])
        // console.dir(msgLangs)
        // return msgLangs
      }
github scalarwaves / leximaven / src / commands / acronym.js View on Github external
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) {
          const found = result.acronym.found[0]
          const count = found.$
          if (count.n === '0') {
            console.log(ctstyle(`Found 0 acronyms for ${acronym}.`))
          } else {
            console.log(ctstyle(`Found ${count.n} acronyms for ${acronym}:`))
            const list = found.acro
            for (let i = 0; i <= list.length - 1; i++) {
              const item = list[i]
              process.stdout.write(ctstyle(`${item.expan}`))
              tofile[[`expansion${i}`]] = item.expan[0]
              const comm = item.comment[0]
              if (comm !== '') {
                if (comm.a) {
github Jintin / transai / lib / android.js View on Github external
files.map(function(name) {
        var raw = fs.readFileSync(name);
        var parser = new xml2js.Parser();
        parser.parseString(raw, function(err, result) {
            if (err) {
                console.error(name + " file has syntax error");
                return;
            }
            var data = result["resources"]["string"];
            if (data) {
                obj = parse(data);
            }
        });
    });
    return obj;
github hyperflow-wms / hyperflow / converters / pegasus_dax.js View on Github external
function parseDax(filename, cb) {
    var self = this;
    var parser = new xml2js.Parser({normalize: true});
    fs.readFile(filename, function(err, data) {
        if (err) {
            cb(new Error("File read error. Doesn't exist?"));
        } else {
            var dag = data.toString();
            dag = dag.replace(//g, "$1");
            dag = dag.replace(//g, "$1");
            parser.parseString(dag, function(err, result) {
                if (err) {
                    cb(new Error("File parse error."));
                } else {
                    //console.log(JSON.stringify(result, null, 2));
                    cb(null, result);
                }
            });
        }
github itgalaxy / webfont / src / standalone.js View on Github external
function getGlyphsData(files, options) {
  const metadataProvider =
    options.metadataProvider ||
    defaultMetadataProvider({
      prependUnicode: options.prependUnicode,
      startUnicode: options.startUnicode
    });

  const xmlParser = new xml2js.Parser();
  const throttle = pLimit(options.maxConcurrency);

  return Promise.all(
    files.map(srcPath =>
      throttle(
        () =>
          new Promise((resolve, reject) => {
            const glyph = fs.createReadStream(srcPath);
            let glyphContents = "";

            return glyph
              .on("error", glyphError => reject(glyphError))
              .on("data", data => {
                glyphContents += data.toString();
              })
              .on("end", () => {
github isleofcode / splicon / src / utils / update-config.js View on Github external
return new RSVP.Promise((resolve, reject) => {
    const contents = fs.readFileSync(xmlPath, 'utf8');
    const parser = new xml2js.Parser();

    if (contents === '') reject('File is empty');

    parser.parseString(contents, function (err, result) {
      if (err) reject(err);
      if (result) resolve(result);
    });
  });
};
github glenmurphy / route / modules / sonos / sonos_experimental.js View on Github external
SonosComponent.prototype.parseMetadata = function (metadata, callback) {
  var parser = new xml2js.Parser();
  parser.parseString(metadata, function (err, result) {
    if (!result) return;

    var metaInfo = {};
    var meta = result["DIDL-Lite"]["item"][0];
    var streamcontent = xmlValue(meta, "r:streamContent");
    streamcontent = this.parseXMStreamContent(streamcontent);
    metaInfo.name =  streamcontent.title || xmlValue(meta, "dc:title");
    metaInfo.url =  meta.res[0]._;
    metaInfo.artist = streamcontent.artist || xmlValue(meta, "dc:creator");
    metaInfo.album = xmlValue(meta, "upnp:album");
    if (xmlValue(meta, "upnp:albumArtURI")) metaInfo.artwork = url.resolve("http://" + this.host + ":" + Sonos.PORT, xmlValue(meta, "upnp:albumArtURI"));
    
    callback(metaInfo);
  }.bind(this));
};
github Geal / Unpapered / src / unpapered.js View on Github external
function e(a, b) {
            var c = require("xml2js");
            (new c.Parser).parseString(a, b)
        }
        return typeof window == "undefined" ? {
github Azure / azure-sdk-for-node / lib / serviceruntime / fileinputchannel.js View on Github external
this._readData(name, function (error, data) {
    if (!error) {
      if (parseXml) {
        var parser = new xml2js.Parser();
        parser.on('error', function (e) { error = e; });
        parser.parseString(data);

        if (parser.resultObject) {
          data = parser.resultObject;
        }
      }

      callback(error, data);
    } else {
      callback(error);
    }
  });
};