mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Let XML node options be set
let msg.options to set a lot more options if required
This commit is contained in:
parent
caa83ac830
commit
fa42fbdab8
@ -23,10 +23,10 @@
|
||||
</div>
|
||||
<div id="advanced-options">
|
||||
<div class="form-row">
|
||||
<i class="fa fa-key"></i> <span data-i18n="xml.label.represent"></span> <input type="text" id="node-input-attr" style="width:20px !important">
|
||||
<i class="fa fa-key"></i> <span data-i18n="xml.label.represent"></span> <input type="text" id="node-input-attr" style="width:20px !important" placeholder="$">
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<i class="fa fa-key"></i> <span data-i18n="xml.label.prefix"></span> <input type="text" id="node-input-chr" style="width:20px !important">
|
||||
<i class="fa fa-key"></i> <span data-i18n="xml.label.prefix"></span> <input type="text" id="node-input-chr" style="width:20px !important" placeholder="_">
|
||||
</div>
|
||||
<div class="form-tips"><span data-i18n="xml.tip"></span></div>
|
||||
</div>
|
||||
@ -36,7 +36,10 @@
|
||||
<p>A function that parses the <b>msg.payload</b> to convert xml to/from a javascript object. Places the result in the payload.</p>
|
||||
<p>If the input is a string it tries to parse it as XML and creates a javascript object.</p>
|
||||
<p>If the input is a javascript object it tries to build an XML string.</p>
|
||||
<p>See <a href="https://github.com/Leonidas-from-XIV/node-xml2js/blob/master/README.md" target="_new">the xml2js docs <i>here</i></a> for more information.</p>
|
||||
<p>You can also pass in a <b>msg.options</b> object to overide all the multitude of parameters. See
|
||||
<a href="https://github.com/Leonidas-from-XIV/node-xml2js/blob/master/README.md" target="_new">the xml2js docs <i>here</i></a>
|
||||
for more information.</p>
|
||||
<p>If set, options in the edit dialogue override those passed in on the msg.options object.</p>
|
||||
</script>
|
||||
|
||||
<script type="text/javascript">
|
||||
@ -45,8 +48,8 @@
|
||||
color:"#DEBD5C",
|
||||
defaults: {
|
||||
name: {value:""},
|
||||
attr: {value:'$',required:true},
|
||||
chr: {value:'_',required:true}
|
||||
attr: {value:""},
|
||||
chr: {value:""}
|
||||
},
|
||||
inputs:1,
|
||||
outputs:1,
|
||||
|
@ -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;
|
||||
|
@ -36,7 +36,7 @@
|
||||
"mustache": "2.1.2",
|
||||
"cron":"1.0.9",
|
||||
"raw-body":"2.1.2",
|
||||
"xml2js":"0.4.9",
|
||||
"xml2js":"0.4.12",
|
||||
"sentiment":"0.2.3",
|
||||
"follow-redirects":"0.0.6",
|
||||
"cors":"2.7.1",
|
||||
|
Loading…
Reference in New Issue
Block a user