Let XML node options be set

let msg.options to set a lot more options if required
This commit is contained in:
Dave Conway-Jones
2015-09-26 13:46:35 +01:00
parent caa83ac830
commit fa42fbdab8
3 changed files with 22 additions and 11 deletions

View File

@@ -22,17 +22,25 @@ module.exports = function(RED) {
function XMLNode(n) {
RED.nodes.createNode(this,n);
this.attrkey = n.attr || '$';
this.charkey = n.chr || '_';
this.attrkey = n.attr;
this.charkey = n.chr;
var node = this;
this.on("input", function(msg) {
if (msg.hasOwnProperty("payload")) {
if (typeof msg.payload == "object") {
msg.payload = builder.buildObject(msg.payload);
if (typeof msg.payload === "object") {
var options = {};
if (msg.hasOwnProperty("options") && typeof msg.options === "object") { options = msg.options; }
options.async = false;
msg.payload = builder.buildObject(msg.payload, options);
node.send(msg);
}
else if (typeof msg.payload == "string") {
parseString(msg.payload, {strict:true,async:true,attrkey:node.attrkey,charkey:node.charkey}, function (err, result) {
var options = {};
if (msg.hasOwnProperty("options") && typeof msg.options === "object") { options = msg.options; }
options.async = true;
options.attrkey = node.attrkey || options.attrkey || '$';
options.charkey = node.charkey || options.charkey || '_';
parseString(msg.payload, options, function (err, result) {
if (err) { node.error(err, msg); }
else {
msg.payload = result;