Parse xml to json
npm install node-red-contrib-xml2jsonxml2json NodeRED Node
=====================
Installing with npm
-------
npm install node-red-contrib-xml2json
Adding nodes to the palette
-------
Using the Editor
You can install nodes directly within the editor by selecting the Manage Palette option from the main menu to open the Palette Manager.
The ‘Nodes’ tab lists all of the modules you have installed. It shows which you are using and whether updates are available for any of them.
The ‘Install’ tab lets you search the catalogue of available node modules and install them.
Example
------
- xml to json
``xml
`
`
json
`
{
"domain": {
"xmlns": "http://www.tmaxsoft.com/xml/ns/jeus",
"version": "7.0",
"id": "1804002829",
"admin-server-name": "myServer",
"servers": {
"server": {
"name": "myServer",
"listeners": {
"base": "base",
"listener": [
{
"name": "base",
"listen-port": "9736"
},
{
"name": "jms-internal",
"listen-port": "9741"
}
]
},
.
.
.
}
`
JS Code for Node-RED
------
js
``
var xml2json = require('xml2json');
module.exports = function (RED) {
function xml2jsonFunction(config) {
RED.nodes.createNode(this, config);
var self = this;
this.on('input', function(msg) {
msg.payload = xml2json.toJson(msg.payload);
self.send(msg);
});
}
RED.nodes.registerType('xml2json', xml2jsonFunction);
};