-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathxml-util.js
More file actions
34 lines (34 loc) · 939 Bytes
/
Copy pathxml-util.js
File metadata and controls
34 lines (34 loc) · 939 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/**
* Created by lixueyang on 2017/5/5.
*/
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const XML2JS = require("xml2js");
const logger_1 = require("./logger");
/**
*
* @param xmlContent XML格式数据
* @returns {Promise<>}
*/
function parse2Json(xmlContent) {
return new Promise((resolve, reject) => {
XML2JS.parseString(xmlContent, { explicitArray: false, ignoreAttrs: true }, (err, data) => {
if (err) {
reject(err);
}
else {
resolve(data.xml);
}
});
});
}
exports.parse2Json = parse2Json;
function buildXML(data) {
const builder = new XML2JS.Builder({ rootName: "xml", cdata: true });
const xml = builder.buildObject(data);
logger_1.default.info(xml);
return xml;
}
exports.buildXML = buildXML;
exports.default = { parse2Json, buildXML };
//# sourceMappingURL=xml-util.js.map