How to use the xml2js.processors 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 meetearnest / aws-sts / src / index.js View on Github external
function *selectRole(samlAssertion, roleName) {
  let buf = new Buffer(samlAssertion, 'base64');
  let saml = yield thunkify(xml2js.parseString)(
    buf,
    {tagNameProcessors: [xml2js.processors.stripPrefix], xmlns: true});

  // Extract SAML roles
  let roles;
  let attributes = saml.Response.Assertion[0].AttributeStatement[0].Attribute;
  for (let attribute of attributes) {
    if (attribute.$.Name.value === 'https://aws.amazon.com/SAML/Attributes/Role') {
      roles = attribute.AttributeValue.map(function (role) {
        return parseRoleAttributeValue(role._);
      });
    }
  }

  if (!roles || roles.length <= 0) {
    throw new Error('No roles are assigned to your SAML account. Please contact Ops.');
  }
github darylturner / node-netconf / lib / netconf.js View on Github external
this.remoteCapabilities = [ ];
    this.idCounter = 100;
    this.rcvBuffer = '';
    this.debug = params.debug;

    // Runtime option tweaks
    this.raw = false;
    this.parseOpts = {
        trim: true,
        explicitArray: false,
        emptyTag: true,
        ignoreAttrs: false,
        tagNameProcessors: [ objectHelper ],
        attrNameProcessors: [ objectHelper ],
        valueProcessors: [ xml2js.processors.parseNumbers ],
        attrValueProcessors: [ xml2js.processors.parseNumbers ]
    };
    this.algorithms = params.algorithms
}
Client.prototype = {
github CumberlandGroup / node-ews / bin / ews.js View on Github external
var parseString = require('xml2js').parseString;
var processors = require('xml2js').processors;
var httpntlm = require('httpntlm');
var debug = require('debug')('node-ews');
var async = require('async');
var soap = require('../node-soap');
var path = require('path');
var tmp = require('tmp');
var fs = require('fs');
var _ = require('lodash');

// constructor
function EWS() {

}

// ntlm authorization
EWS.prototype.auth = function(username, password, ewsHost) {
github ging / fiware-pep-proxy / lib / azf.js View on Github external
proxy.sendData(config.azf.protocol, options, xml, undefined, function (status, resp) {
            log.debug("AZF response status: ", status);
            log.debug("AZF response: ", resp);
            var decision;
            // xml2json keeps namespace prefixes in json keys, which is not right because prefixes are not supposed to be fixed; only the namespace URIs they refer to
            // After parsing to JSON, we need to extract the Decision element in XACML namespace..
            // But there does not seem to be any good npm packge supporting namespace-aware XPath or equivalent evaluation on JSON. 
            // (xml2js-xpath will probably support namespaces in the next release: https://github.com/dsummersl/node-xml2js-xpath/issues/5 ) 
            // The easy way to go (but with inconvenients) is to get rid of prefixes.One way to refixes is to use npm package 'xml2js' with stripPrefix option.
            xml2js.parseString(resp, {tagNameProcessors: [xml2js.processors.stripPrefix]}, function(err, json_res) {
              log.debug("AZF response parsing result (JSON): ", json_res);
              log.debug("AZF response parsing error ('null' means no error): ", err);
              // xml2js puts child nodes in array by default, except on the root node (option 'explicitArray')
              decision = json_res.Response.Result[0].Decision[0];
            });
            
            decision = String(decision);

            log.debug('Decision: ', decision);
            if (decision === 'Permit') {
                success();
            } else {
                error(401, 'User not authorized in AZF for the given action and resource');
            }
        }, error);
    };
github jembi / openhim-core-js / src / auditing.js View on Github external
import logger from 'winston'
import { Parse as syslogParser } from 'glossy'
import { parseString } from 'xml2js'
import dgram from 'dgram'
import tls from 'tls'
import net from 'net'

import { AuditModel, AuditMetaModel } from './model/audits'
import * as tlsAuthentication from './middleware/tlsAuthentication'
import { config } from './config'

config.auditing = config.get('auditing')
const { firstCharLowerCase } = require('xml2js').processors

function parseAuditRecordFromXML (xml, callback) {
  // DICOM mappers
  function csdCodeToCode (name) {
    if (name === 'csd-code') { return 'code' }
    return name
  }

  function originalTextToDisplayName (name) {
    if (name === 'originalText') { return 'displayName' }
    return name
  }

  const options = {
    mergeAttrs: true,
    explicitArray: false,
github volumio / Volumio2 / app / plugins / music_service / upnp_browser / dlna-browser.js View on Github external
// Copyright 2016 the project authors as listed in the AUTHORS file.
// All rights reserved. Use of this source code is governed by the
// license that can be found in the LICENSE file.
"use strict";
const http = require('http');
const url = require('url');
const xmlbuilder = require('xmlbuilder');
const xmltojs =  require('xml2js');
const stripPrefix = require('xml2js').processors.stripPrefix;
const Entities = require('html-entities').XmlEntities;

const entities = new Entities();

var debug = false;


// function to build the xml required for the saop request to the DLNA server
const buildRequestXml = function(id, options) {
  // fill in the defaults
  if (!options.browseFlag) {
    options.browseFlag = 'BrowseDirectChildren';
  }

  if (!options.filter) {
    options.filter = '*';
github FIWARE / tutorials.Step-by-Step / context-provider / lib / azf.js View on Github external
request(options, function(error, response, body) {
      let decision;
      xml2js.parseString(
        body,
        { tagNameProcessors: [xml2js.processors.stripPrefix] },
        function(err, jsonRes) {
          decision = jsonRes.Response.Result[0].Decision[0];
        }
      );
      debug('policyDomainRequest returns:' + decision);
      return error ? reject(error) : resolve(decision);
    });
  });
github Andro999b / torrent-player / server / dlna / upnp-server / Server.js View on Github external
let actionName = req.headers['SOAPACTION'] || req.headers['soapaction']
        actionName =
            actionName &&
            actionName.substring(
                actionName.lastIndexOf('#') + 1,
                actionName.length - 1
            )

        if (service && actionName) {
            xml2js.parseString(
                req.data,
                {
                    mergeAttrs: true,
                    explicitArray: false,
                    tagNameProcessors: [xml2js.processors.stripPrefix],
                    ignoreAttrs: true
                },
                (err, json) => {
                    if (err) {
                        res.statusCode = 400
                        res.end(`Request is not a valide XML message: ${err.message}`)
                        debug(`Bad xml request: ${req.data}`)
                    } else {
                        try {
                            let inputs = json.Envelope.Body[actionName]

                            debug(`Service controll input: ${inputs}`)

                            if (typeof inputs == 'undefined') {
                                throw new Error()
                            }
github mkopit / url-embed / lib / classes / OEmbedProvider.js View on Github external
body = this.convertHighBitUnicodeToSurrogates(body);
    let data;
    if (this.format === 'json') {
      try {
        data = JSON.parse(body);
        callback(null, data);
      } catch (error) {
        callback(error);
      }
      return;
    } else {
      let xmlOptions = {
        explicitArray: false,
        valueProcessors: [
          xml2js.processors.parseNumbers,
          xml2js.processors.parseBooleans
        ]
      };
      data = xml2js.parseString(body, xmlOptions, function (error, result) {
        if (error) {
          callback(error);
        } else {
          data = result.oembed;
          callback(null, data);
        }
        return;
      });
    }
  }