1
0
mirror of https://github.com/node-red/node-red.git synced 2023-10-10 13:36:53 +02:00

new-style callback function (xml node)

This commit is contained in:
Kunihiko Toumura 2019-11-29 16:55:51 +09:00
parent a19dab0dc9
commit 0eda0a4935

View File

@ -10,7 +10,7 @@ module.exports = function(RED) {
this.charkey = n.chr; this.charkey = n.chr;
this.property = n.property||"payload"; this.property = n.property||"payload";
var node = this; var node = this;
this.on("input", function(msg) { this.on("input", function(msg,send,done) {
var value = RED.util.getMessageProperty(msg,node.property); var value = RED.util.getMessageProperty(msg,node.property);
if (value !== undefined) { if (value !== undefined) {
var options; var options;
@ -21,7 +21,8 @@ module.exports = function(RED) {
var builder = new xml2js.Builder(options); var builder = new xml2js.Builder(options);
value = builder.buildObject(value, options); value = builder.buildObject(value, options);
RED.util.setMessageProperty(msg,node.property,value); RED.util.setMessageProperty(msg,node.property,value);
node.send(msg); send(msg);
done();
} }
else if (typeof value == "string") { else if (typeof value == "string") {
options = {}; options = {};
@ -30,17 +31,18 @@ module.exports = function(RED) {
options.attrkey = node.attrkey || options.attrkey || '$'; options.attrkey = node.attrkey || options.attrkey || '$';
options.charkey = node.charkey || options.charkey || '_'; options.charkey = node.charkey || options.charkey || '_';
parseString(value, options, function (err, result) { parseString(value, options, function (err, result) {
if (err) { node.error(err, msg); } if (err) { done(err); }
else { else {
value = result; value = result;
RED.util.setMessageProperty(msg,node.property,value); RED.util.setMessageProperty(msg,node.property,value);
node.send(msg); send(msg);
done();
} }
}); });
} }
else { node.warn(RED._("xml.errors.xml_js")); } else { node.warn(RED._("xml.errors.xml_js")); done(); }
} }
else { node.send(msg); } // If no property - just pass it on. else { send(msg); done(); } // If no property - just pass it on.
}); });
} }
RED.nodes.registerType("xml",XMLNode); RED.nodes.registerType("xml",XMLNode);