mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Let xml node set options both ways
to close #1022 to close #975 Thanks @martin-doyle and @nikhildx
This commit is contained in:
parent
5d98a86a6b
commit
aa8ad60083
@ -18,7 +18,6 @@ module.exports = function(RED) {
|
||||
"use strict";
|
||||
var xml2js = require('xml2js');
|
||||
var parseString = xml2js.parseString;
|
||||
var builder = new xml2js.Builder({renderOpts:{pretty:false}});
|
||||
|
||||
function XMLNode(n) {
|
||||
RED.nodes.createNode(this,n);
|
||||
@ -27,15 +26,17 @@ module.exports = function(RED) {
|
||||
var node = this;
|
||||
this.on("input", function(msg) {
|
||||
if (msg.hasOwnProperty("payload")) {
|
||||
var options;
|
||||
if (typeof msg.payload === "object") {
|
||||
var options = {};
|
||||
options = {renderOpts:{pretty:false}};
|
||||
if (msg.hasOwnProperty("options") && typeof msg.options === "object") { options = msg.options; }
|
||||
options.async = false;
|
||||
var builder = new xml2js.Builder(options);
|
||||
msg.payload = builder.buildObject(msg.payload, options);
|
||||
node.send(msg);
|
||||
}
|
||||
else if (typeof msg.payload == "string") {
|
||||
var options = {};
|
||||
options = {};
|
||||
if (msg.hasOwnProperty("options") && typeof msg.options === "object") { options = msg.options; }
|
||||
options.async = true;
|
||||
options.attrkey = node.attrkey || options.attrkey || '$';
|
||||
|
Loading…
Reference in New Issue
Block a user