Ber*_*lue 3 amazon-web-services node.js xml-parsing aws-lambda
是否可以在AWS Node.js Lambda函数中进行XML解析而不使用像xml2js这样的第三方模块?我想知道AWS是否具有任何内置功能,就像在AWS SDK for Node.js中一样.
实际上我只测试了这个,你可以直接使用xml2js开箱即用,因为......
https://github.com/aws/aws-sdk-js/blob/master/lib/xml/node_parser.js
这就是AWS JS SDK使用的内容.示例Lambda代码用于测试它,完全使用Lambda在线编辑器并针对它运行测试数据:
'use strict';
var xml2js = require('xml2js');
console.log('Loading function');
var options = { // options passed to xml2js parser
explicitCharkey: false, // undocumented
trim: false, // trim the leading/trailing whitespace from text nodes
normalize: false, // trim interior whitespace inside text nodes
explicitRoot: false, // return the root node in the resulting object?
emptyTag: null, // the default value for empty nodes
explicitArray: true, // always put child nodes in an array
ignoreAttrs: false, // ignore attributes, only create text nodes
mergeAttrs: false, // merge attributes and child elements
validator: null // a callable validator
};
exports.handler = (event, context, callback) => {
var parser = new xml2js.Parser(options);
//console.log('Received event:', JSON.stringify(event, null, 2));
console.log('value1 =', event.key1);
console.log('value2 =', event.key2);
console.log('value3 =', event.key3);
callback(null, event.key1); // Echo back the first key value
//callback('Something went wrong');
};
Run Code Online (Sandbox Code Playgroud)
也就是说,如果你想避开这条路线,你将不得不采用标准的包装安装路线.
| 归档时间: |
|
| 查看次数: |
4095 次 |
| 最近记录: |