久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

使用外部 js 庫在 Amazon Lambda 中將 XML 解析為 JSO

Parsing XML to JSON in Amazon Lambda using external js libraries(使用外部 js 庫在 Amazon Lambda 中將 XML 解析為 JSON)
本文介紹了使用外部 js 庫在 Amazon Lambda 中將 XML 解析為 JSON的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

我正在嘗試將我從服務(wù)器獲取的 XML 字符串轉(zhuǎn)換為我的 Lambda 函數(shù)中的 JSON.
我已經(jīng)設(shè)置了這個相當(dāng)簡單的示例來模擬我使用 DynamoDB 從服務(wù)器獲得的 XML 答案.(目前我只是在嘗試進(jìn)行轉(zhuǎn)換)

I am trying to convert an XML String that I get from a server to JSON inside my Lambda function.
I have set up this rather simple example to simulate the XML answer that i get from the server using DynamoDB. (Currently I'm just trying to get the convertion going)

'use strict';

var AWS = require('aws-sdk');
var docClient = new AWS.DynamoDB.DocumentClient({region: 'eu-west-1'});


exports.handler = function (e, ctx, callback){    
    let table = "dsbTable";
    let bpNumber = 1337;
    var test;
    var x2js = new X2JS();
    let params = {
            TableName: table,
            Key:{
                "bpNumber": bpNumber
            },
        };
    docClient.get(params, function(err, data) {
            if (err) {
                console.error("Unable to read item. Error JSON:", JSON.stringify(err, null, 2));
                callback(err, null);
            } else {
                console.log("GetItem succeeded:", JSON.stringify(data, null, 2));
                console.log('test' +data.Item.getBp);
                //var jsonObj = x2js.xml_str2json(data.Item.getBp);
                //console.log(jsonObj);

                callback(null, data);
            }

    });

}  ;

獲取項目工作正常,并像這樣返回

getting the item works just fine and is returned like this

{
  "Item": {
    "getBp": "<message version="1.0" system="AVS/3"><header><client>553</client><avs3-sales-organization>7564</avs3-sales-organization><avs3-service-provider>DSD</avs3-service-provider></header><body><business-partner><salutation-code>01</salutation-code><titel-code-academic/><titel-academic/><titel-code-royal/><titel-royal/><job-titel/><last-name1>Pickle</last-name1><last-name2/><first-name>N</first-name><street/><street-suffix/><street-number/><street-number-suffix/><address-line-1>10 Waterside Way</address-line-1><address-line-2/><address-line-3/><zipcode>NN4 7XD</zipcode><country-code>GB</country-code><city>NORTHAMPTON</city><district/><region-code>NH</region-code><region-text>Northamptonshire</region-text><company1/><company2/><company3/><department/><po-box/><po-box-zipcode/><po-box-city/><po-box-country-code/><major-customer-zipcode/><address-source/><advertisement>Y</advertisement><category/><bp-number>1100000772</bp-number><bp-number-external/><bp-group>ABON</bp-group><eu-sales-tax-number/><bic-master-number/><sector/><communication><communication-type>WW</communication-type><communication-value>kate.southorn@dsbnet.co.uk</communication-value><communication-default>Y</communication-default></communication><attribute><attribute-type>ACC</attribute-type><attribute-value>Y</attribute-value></attribute><attribute><attribute-type>OIEMEX</attribute-type><attribute-value>N20121211</attribute-value></attribute><attribute><attribute-type>OINLIN</attribute-type><attribute-value>N20121211</attribute-value></attribute><attribute><attribute-type>OISMEX</attribute-type><attribute-value>N20121211</attribute-value></attribute><attribute><attribute-type>OISMIN</attribute-type><attribute-value>N20121211</attribute-value></attribute><attribute><attribute-type>OOEMIN</attribute-type><attribute-value>N20121211</attribute-value></attribute><attribute><attribute-type>OOFXEX</attribute-type><attribute-value>N20121211</attribute-value></attribute><attribute><attribute-type>OOFXIN</attribute-type><attribute-value>N20121211</attribute-value></attribute><attribute><attribute-type>OOPTEX</attribute-type><attribute-value>N20121211</attribute-value></attribute><attribute><attribute-type>OOPTIN</attribute-type><attribute-value>N20121211</attribute-value></attribute><attribute><attribute-type>OOTEEX</attribute-type><attribute-value>N20121211</attribute-value></attribute><attribute><attribute-type>OOTEIN</attribute-type><attribute-value>N20121211</attribute-value></attribute><attribute><attribute-type>THEDSU</attribute-type><attribute-value/></attribute></business-partner></body></message>",
    "bpNumber": 1337
  }
}

我現(xiàn)在的主要問題是我不知道如何導(dǎo)入任何 XMLtoJSON 庫文件,例如 這里的這個

My main issue now is that I can not figure out how i can import any XMLtoJSON library files like this one here

我希望我在這種情況下的代碼不是完全沒有價值,并且有一個相當(dāng)簡單的解決方案.

I hope my code in this case is not completely worthless and there is a rather simple solution.

推薦答案

您正在經(jīng)歷許多新的 Lambda 用戶所走過的道路.

You're going through the path that many new Lambda users have gone.

使用 Lambda,這非常簡單,您只需編寫代碼并驗證它是否按預(yù)期工作 - 我的意思是在您的計算機(jī)上.

With Lambda, it is absolutely easy, you just write your code and validate that it works as expected - I mean on your computer.

驗證后,請執(zhí)行以下操作:

Once you have validated it, do as follows:

  1. 壓縮整個文件夾的內(nèi)容,包括 node_modules 目錄以及您使用的任何依賴項.
  2. 將其上傳到 Lambda.

如果您不小心也壓縮了包含文件夾,那很好,只需確保更新 Lambda 以從以下位置運(yùn)行腳本:dir_name/file_name.function_name(不要不要忘記從你的模塊中導(dǎo)出 function_name).

If you accidentally zipped the containing folder as well, that is fine, just make sure to update Lambda to run the script from: dir_name/file_name.function_name (don't forget to export function_name from your module).

這篇關(guān)于使用外部 js 庫在 Amazon Lambda 中將 XML 解析為 JSON的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

discord.js v12: How do I await for messages in a DM channel?(discord.js v12:我如何等待 DM 頻道中的消息?)
how to make my bot mention the person who gave that bot command(如何讓我的機(jī)器人提及發(fā)出該機(jī)器人命令的人)
How to fix Must use import to load ES Module discord.js(如何修復(fù)必須使用導(dǎo)入來加載 ES 模塊 discord.js)
How to list all members from a specific server?(如何列出來自特定服務(wù)器的所有成員?)
Discord bot: Fix ‘FFMPEG not found’(Discord bot:修復(fù)“找不到 FFMPEG)
Welcome message when joining discord Server using discord.js(使用 discord.js 加入 discord 服務(wù)器時的歡迎消息)
主站蜘蛛池模板: 男女黄网站 | 亚洲欧美日韩高清 | 噜噜噜色网 | 成人午夜性成交 | 日本三级电影在线免费观看 | 日韩中文字幕视频在线观看 | 国产一区二区三区四区五区加勒比 | 欧美一级视频 | 久久r久久 | 欧美日韩在线免费观看 | 黄页网址在线观看 | 日操操| 91大神在线资源观看无广告 | 欧美一级欧美三级在线观看 | 精品国产一区二区国模嫣然 | 国产亚洲二区 | 亚洲欧美综合网 | 国产中文| 久久青| 在线观看日韩av | 中文字幕av在线一二三区 | 夜夜夜夜草 | 91久久久久久久久久久 | 国产精品国产三级国产aⅴ入口 | 中文久久| 视频一区二区中文字幕 | 欧美日韩中文字幕在线 | 中文福利视频 | 国产日韩一区二区三区 | 亚洲成人自拍网 | 91中文在线观看 | 欧美天堂 | 国产精品揄拍一区二区 | 久久福利电影 | 欧美综合一区 | 一区二区三区四区在线播放 | 国产精品久久久久久久久久久久冷 | 精品亚洲一区二区三区四区五区高 | 亚洲电影专区 | 色桃网| 亚洲天堂日韩精品 |