lib/types/xml.js
function xmlparser(options) {

  var parserOptions = util._extend({
      async: false,
      explicitArray: true,
      normalize: true,
      normalizeTags: true,
      trim: true
    }, options || {});

  return xmlbodyparser;
  
  /**
   * Provide connect/express-style middleware
   *
   * @param {IncomingMessage} req
   * @param {ServerResponse} res
   * @param {Function} next
   * @return {*}
   */

  function xmlbodyparser(req, res, next) {

    var data = '';

    var parser = new xml2js.Parser(parserOptions);

    /**
     * @param {Error} err
     * @param {Object} [xml]
     */

    var responseHandler = function (err, xml) {
        if (err) {
          err.status = 400;
          return next(err);
        }

        req.body = xml || req.body;
        req.rawBody = data;
        next();
    };

    if (req._body) {
      return next();
    }

    req.body = req.body || {};

    if (!hasBody(req) || !module.exports.regexp.test(mime(req))) {
      return next();
    }

    req._body = true;

    // explicitly cast incoming to string
    req.setEncoding('utf-8');
    req.on('data', function (chunk) {
      data += chunk;
    });

    // in case `parseString` callback never was called, ensure response is sent
    parser.saxParser.onend = function() {
      if (req.complete && req.rawBody === undefined) {
        return responseHandler(null);
      }
    };

    req.on('end', function () {

      // invalid xml, length required
      if (data.trim().length === 0) {
        return next(error(411));
      }

      parser.parseString(data, responseHandler);

    });
  }

}
function xmlparser(options) {

  var parserOptions = util._extend({
      async: false,
      explicitArray: true,
      normalize: true,
      normalizeTags: true,
      trim: true
    }, options || {});

  return xmlbodyparser;
  
  /**
   * Provide connect/express-style middleware
   *
   * @param {IncomingMessage} req
   * @param {ServerResponse} res
   * @param {Function} next
   * @return {*}
   */

  function xmlbodyparser(req, res, next) {

    var data = '';

    var parser = new xml2js.Parser(parserOptions);

    /**
     * @param {Error} err
     * @param {Object} [xml]
     */

    var responseHandler = function (err, xml) {
        if (err) {
          err.status = 400;
          return next(err);
        }

        req.body = xml || req.body;
        req.rawBody = data;
        next();
    };

    if (req._body) {
      return next();
    }

    req.body = req.body || {};

    if (!hasBody(req) || !module.exports.regexp.test(mime(req))) {
      return next();
    }

    req._body = true;

    // explicitly cast incoming to string
    req.setEncoding('utf-8');
    req.on('data', function (chunk) {
      data += chunk;
    });

    // in case `parseString` callback never was called, ensure response is sent
    parser.saxParser.onend = function() {
      if (req.complete && req.rawBody === undefined) {
        return responseHandler(null);
      }
    };

    req.on('end', function () {

      // invalid xml, length required
      if (data.trim().length === 0) {
        return next(error(411));
      }

      parser.parseString(data, responseHandler);

    });
  }

}
function xmlparser ( options ) { var parserOptions = util . _extend ( { async : false , explicitArray : true , normalize : true , normalizeTags : true , trim : true } , options || { } ) ; return xmlbodyparser ; /**
   * Provide connect/express-style middleware
   *
   * @param {IncomingMessage} req
   * @param {ServerResponse} res
   * @param {Function} next
   * @return {*}
   */ function xmlbodyparser ( req , res , next ) { var data = '' ; var parser = new xml2js . Parser ( parserOptions ) ; /**
     * @param {Error} err
     * @param {Object} [xml]
     */ var responseHandler = function ( err , xml ) { if ( err ) { err . status = 400 ; return next ( err ) ; } req . body = xml || req . body ; req . rawBody = data ; next ( ) ; } ; if ( req . _body ) { return next ( ) ; } req . body = req . body || { } ; if ( ! hasBody ( req ) || ! module . exports . regexp . test ( mime ( req ) ) ) { return next ( ) ; } req . _body = true ; // explicitly cast incoming to string req . setEncoding ( 'utf-8' ) ; req . on ( 'data' , function ( chunk ) { data += chunk ; } ) ; // in case `parseString` callback never was called, ensure response is sent parser . saxParser . onend = function ( ) { if ( req . complete && req . rawBody === undefined ) { return responseHandler ( null ) ; } } ; req . on ( 'end' , function ( ) { // invalid xml, length required if ( data . trim ( ) . length === 0 ) { return next ( error ( 411 ) ) ; } parser . parseString ( data , responseHandler ) ; } ) ; } }
Expose configuration for xml-bodyparser middleware

@api public
@param {Object} [options] Parser options
@return {Function}
Expose configuration for xml - bodyparser middleware