mirror of
https://github.com/node-red/node-red.git
synced 2023-10-10 13:36:53 +02:00
Added error trap to xml2js node.
This commit is contained in:
parent
612dd4dc7f
commit
3b60e1a0e3
@ -15,39 +15,39 @@
|
||||
-->
|
||||
|
||||
<script type="text/x-red" data-template-name="xml2js">
|
||||
<div class="form-row">
|
||||
<label>Use Console</label>
|
||||
<input type="checkbox" id="node-input-useEyes" placeholder="Name" style="display: inline-block; width: auto; vertical-align: top;">
|
||||
<label for="node-input-useEyes" style="width: 70%;">Debug output in console ?</label>
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label for="node-input-name"><i class="icon-tag"></i> Name</label>
|
||||
<input type="text" id="node-input-name" placeholder="Name">
|
||||
</div>
|
||||
<div class="form-tips">Uses xml2js to process xml into javascript object.</div>
|
||||
<div class="form-row">
|
||||
<label>Use Console</label>
|
||||
<input type="checkbox" id="node-input-useEyes" placeholder="Name" style="display: inline-block; width: auto; vertical-align: top;">
|
||||
<label for="node-input-useEyes" style="width: 70%;">Debug output in console ?</label>
|
||||
</div>
|
||||
<div class="form-row">
|
||||
<label for="node-input-name"><i class="icon-tag"></i> Name</label>
|
||||
<input type="text" id="node-input-name" placeholder="Name">
|
||||
</div>
|
||||
<div class="form-tips">Uses xml2js to process xml into javascript object.</div>
|
||||
</script>
|
||||
|
||||
<script type="text/x-red" data-help-name="xml2js">
|
||||
<p>A function that parses the <b>msg.payload</b> using the xml2js library. Places the result in the payload.</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>A function that parses the <b>msg.payload</b> using the xml2js library. Places the result in the payload.</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>
|
||||
</script>
|
||||
|
||||
<script type="text/javascript">
|
||||
RED.nodes.registerType('xml2js',{
|
||||
category: 'advanced-function',
|
||||
color:"#E6E0F8",
|
||||
defaults: {
|
||||
useEyes: {value:false},
|
||||
name: {value:""},
|
||||
},
|
||||
inputs:1,
|
||||
outputs:1,
|
||||
icon: "arrow-in.png",
|
||||
label: function() {
|
||||
return this.name||"xml2js";
|
||||
},
|
||||
labelStyle: function() {
|
||||
return this.name?"node_label_italic":"";
|
||||
}
|
||||
});
|
||||
RED.nodes.registerType('xml2js',{
|
||||
category: 'advanced-function',
|
||||
color:"#E6E0F8",
|
||||
defaults: {
|
||||
useEyes: {value:false},
|
||||
name: {value:""},
|
||||
},
|
||||
inputs:1,
|
||||
outputs:1,
|
||||
icon: "arrow-in.png",
|
||||
label: function() {
|
||||
return this.name||"xml2js";
|
||||
},
|
||||
labelStyle: function() {
|
||||
return this.name?"node_label_italic":"";
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
@ -19,27 +19,28 @@ var util = require("util");
|
||||
var parseString = require('xml2js').parseString;
|
||||
var gotEyes = false;
|
||||
try {
|
||||
var eyes = require("eyes");
|
||||
gotEyes = true;
|
||||
var eyes = require("eyes");
|
||||
gotEyes = true;
|
||||
} catch(e) {
|
||||
util.log("[73-parsexml.js] Warning: Module 'eyes' not installed");
|
||||
util.log("[73-parsexml.js] Note: Module 'eyes' not installed. (not needed, but useful)");
|
||||
}
|
||||
|
||||
function Xml2jsNode(n) {
|
||||
RED.nodes.createNode(this,n);
|
||||
this.useEyes = n.useEyes;
|
||||
var node = this;
|
||||
|
||||
this.on("input", function(msg) {
|
||||
parseString(msg.payload, function (err, result) {
|
||||
msg.payload = result;
|
||||
node.send(msg);
|
||||
if (node.useEyes == true) {
|
||||
if (gotEyes == true) { eyes.inspect(msg); }
|
||||
else { node.log(JSON.stringify(msg)); }
|
||||
}
|
||||
});
|
||||
});
|
||||
RED.nodes.createNode(this,n);
|
||||
this.useEyes = n.useEyes;
|
||||
var node = this;
|
||||
this.on("input", function(msg) {
|
||||
parseString(msg.payload, function (err, result) {
|
||||
if (err) { node.error(err; }
|
||||
else {
|
||||
msg.payload = result;
|
||||
node.send(msg);
|
||||
if (node.useEyes == true) {
|
||||
if (gotEyes == true) { eyes.inspect(msg); }
|
||||
else { node.log(JSON.stringify(msg)); }
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
RED.nodes.registerType("xml2js",Xml2jsNode);
|
||||
|
Loading…
Reference in New Issue
Block a user