How to use the xml2js.parseString 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 le-doux / bitsy / experiments / font / arabic2-bitsy / ttx_to_bitsyfont.js View on Github external
fs.readFile("bitsy-with-arabic.ttx", "utf8", function(err, data) {
	// console.log(data);
	// console.log(xml2js);
	xml2js.parseString(data, function(err, result) {
		var bitsyFontData = "FONT arabic\n";

		var font = result.ttFont;

		var head = font.head[0];
		function getHeadValue(id) {
			return head[id][0]["$"]["value"];
		}

		var unitsPerEm = getHeadValue("unitsPerEm");
		var pixelsPerEm = getHeadValue("lowestRecPPEM");
		// 8 / 4096 = 0.001953125
		// 4096 / 8 = 512
		var pixelsPerUnit = pixelsPerEm / unitsPerEm; // pixelsPerUnit = 0.001953125
		var unitsPerPixel = unitsPerEm / pixelsPerEm; // unitsPerPixel = 512
github dominickp / JMF-Subscription / JmfSubscriptionServer.js View on Github external
request.on('end', function () {
        // Attempt to parse the XML
        parseString(body, {trim: true}, function (err, result) {
            // Log the body of the request
            //var jsonResult = JSON.parse(result);
            
            var fullResult = util.inspect(result, false, null);
            
            if(err){
                winston.error("Parse error" + err);
            }
            
            if(typeof result["JMF"]["Signal"][0]["DeviceInfo"] !== 'undefined'){
                winston.info('Subscription Update', { 
                        DeviceID: result["JMF"]["Signal"][0]["DeviceInfo"][0]["$"]["DeviceID"],
                        DeviceStatus: result["JMF"]["Signal"][0]["DeviceInfo"][0]["$"]["DeviceStatus"],
                        StatusDetails: result["JMF"]["Signal"][0]["DeviceInfo"][0]["$"]["StatusDetails"],
                        ProductionCounter: result["JMF"]["Signal"][0]["DeviceInfo"][0]["$"]["ProductionCounter"]
                    }
github node-red / node-red-nodes / hardware / wemo / lib / wemo.js View on Github external
request.get(location.href, function(err, res, xml) {
      if (!err) {
        xml2js.parseString(xml, function(err, json) {
          if (!err && json && json.root) {
            var device = { ip: location.hostname, port: location.port };
            for (var key in json.root.device[0]) {
              device[key] = json.root.device[0][key][0];
            }
            if (device.deviceType == "urn:Belkin:device:bridge:1") {
              //console.log( device.ip + ' -' + device.deviceType);
              var ip = device.ip;
              var port = device.port;
              var udn = device.UDN;
              var postoptions = {
                host: ip,
                port: port,
                path: getenddevs.path,
                method: 'POST',
                headers: {
github thlorenz / exmala / non-streaming / parse-stream.js View on Github external
function onend() {
    if (!to_s) {
      var buf = Buffer.concat(bufs);
      xml2js.parseString(buf, cb);
    } else {
      xml2js.parseString(data, cb);
    }
  }
}
github huaweicloud / huaweicloud-sdk-nodejs-obs / lib / utils.js View on Github external
function makeObjFromXml(xml, methodName, log, bc){
	xml2js.parseString(xml, {explicitArray:false, ignoreAttrs:true}, function(err, result){
		if(err){
			return bc(err, null);
		}
		
		if(result === null || result === undefined){
			if(log.isLevelEnabled('error')){
				log.runLog('error', methodName, 'xml [' + xml + '] is not well-format');
			}
			return bc(new Error('xml is not well format'), null);
		}
		
		bc(null, result);
	});
}
github snapserv / keepass.io / lib / KeePass / KeePassDatabase.js View on Github external
function parseAsXml(database, callback) {
				database = xml2js.parseString(database, {explicitArray: false}, function(err, database) {
					if(err) return callback(new Errors.Database('Could not parse database as XML: ' + err.toString()));
					return callback(null, database);
				});
			}.$bind(this),
github undefinedfm / undefined.fm / plugins / gatsby-source-simplecast-rss / internals.js View on Github external
new Promise((resolve, reject) =>
    parseString(i, (e, p) => (e ? reject(e) : resolve(p)))
  );
github JetBrains / teamcity-vscode-extension / src / bll / utils / xmlparser.ts View on Github external
return await new Promise((resolve, reject) => {
            xml2js.parseString(buildXml, (err, buildObj) => {
                if (err) {
                    reject(err);
                }
                const build: Build = Build.fromRestParcedObject(buildObj);
                resolve(build);
            });
        });
    }
github MuYunyun / yunban / wechat / util.js View on Github external
return new Promise(function(resolve, reject) {
		xml2js.parseString(xml, {trim: true}, function(err, content) {
			if (err) {reject(err);}
			else {resolve(content);}
		});
	});
};