[
{
"id": "xml_sample_tab",
"type": "tab",
"label": "XML サンプル",
"disabled": false,
"info": ""
},
{
"id": "xml_comment1",
"type": "comment",
"z": "xml_sample_tab",
"name": "━━━ XML → オブジェクト変換 ━━━",
"info": "",
"x": 180,
"y": 40,
"wires": []
},
{
"id": "xml_inject1",
"type": "inject",
"z": "xml_sample_tab",
"name": "実行",
"props": [],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"x": 130,
"y": 100,
"wires": [["xml_template1"]]
},
{
"id": "xml_template1",
"type": "template",
"z": "xml_sample_tab",
"name": "XML文字列",
"field": "payload",
"fieldType": "msg",
"format": "text",
"syntax": "plain",
"template": "\n
\n \n Node-RED入門\n 山田太郎\n 2500\n \n \n IoT実践ガイド\n 鈴木花子\n 3000\n \n",
"output": "str",
"x": 290,
"y": 100,
"wires": [["xml_parse"]]
},
{
"id": "xml_parse",
"type": "xml",
"z": "xml_sample_tab",
"name": "XML→Obj",
"property": "payload",
"attr": "",
"chr": "",
"x": 450,
"y": 100,
"wires": [["xml_debug1"]]
},
{
"id": "xml_debug1",
"type": "debug",
"z": "xml_sample_tab",
"name": "オブジェクト出力",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"x": 620,
"y": 100,
"wires": []
},
{
"id": "xml_comment2",
"type": "comment",
"z": "xml_sample_tab",
"name": "━━━ オブジェクト → XML変換 ━━━",
"info": "",
"x": 180,
"y": 180,
"wires": []
},
{
"id": "xml_inject2",
"type": "inject",
"z": "xml_sample_tab",
"name": "実行",
"props": [],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"x": 130,
"y": 240,
"wires": [["xml_func1"]]
},
{
"id": "xml_func1",
"type": "function",
"z": "xml_sample_tab",
"name": "オブジェクト生成",
"func": "msg.payload = {\n \"order\": {\n \"$\": { \"id\": \"ORD-001\" },\n \"customer\": \"田中商店\",\n \"items\": {\n \"item\": [\n { \"name\": \"商品A\", \"qty\": \"2\" },\n { \"name\": \"商品B\", \"qty\": \"1\" }\n ]\n },\n \"total\": \"5000\"\n }\n};\nreturn msg;",
"outputs": 1,
"timeout": 0,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 300,
"y": 240,
"wires": [["xml_build"]]
},
{
"id": "xml_build",
"type": "xml",
"z": "xml_sample_tab",
"name": "Obj→XML",
"property": "payload",
"attr": "",
"chr": "",
"x": 470,
"y": 240,
"wires": [["xml_debug2"]]
},
{
"id": "xml_debug2",
"type": "debug",
"z": "xml_sample_tab",
"name": "XML出力",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"x": 620,
"y": 240,
"wires": []
},
{
"id": "xml_comment3",
"type": "comment",
"z": "xml_sample_tab",
"name": "━━━ データ抽出の例 ━━━",
"info": "",
"x": 160,
"y": 320,
"wires": []
},
{
"id": "xml_inject3",
"type": "inject",
"z": "xml_sample_tab",
"name": "実行",
"props": [],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"x": 130,
"y": 380,
"wires": [["xml_template2"]]
},
{
"id": "xml_template2",
"type": "template",
"z": "xml_sample_tab",
"name": "センサーXML",
"field": "payload",
"fieldType": "msg",
"format": "text",
"syntax": "plain",
"template": "
\n \n 25.5\n 2024-01-15T10:30:00\n \n \n 60\n 2024-01-15T10:30:00\n \n",
"output": "str",
"x": 290,
"y": 380,
"wires": [["xml_parse2"]]
},
{
"id": "xml_parse2",
"type": "xml",
"z": "xml_sample_tab",
"name": "XML→Obj",
"property": "payload",
"attr": "",
"chr": "",
"x": 450,
"y": 380,
"wires": [["xml_func2"]]
},
{
"id": "xml_func2",
"type": "function",
"z": "xml_sample_tab",
"name": "温度抽出",
"func": "// センサーデータから温度を抽出\nvar sensors = msg.payload.sensors.sensor;\nvar tempSensor = sensors.find(s => s.$.type === \"temperature\");\n\nmsg.payload = {\n sensorId: tempSensor.$.id,\n value: parseFloat(tempSensor.value[0]._),\n unit: tempSensor.value[0].$.unit,\n timestamp: tempSensor.timestamp[0]\n};\nreturn msg;",
"outputs": 1,
"timeout": 0,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 600,
"y": 380,
"wires": [["xml_debug3"]]
},
{
"id": "xml_debug3",
"type": "debug",
"z": "xml_sample_tab",
"name": "温度データ",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": true,
"complete": "payload",
"targetType": "msg",
"statusVal": "payload.value",
"statusType": "msg",
"x": 770,
"y": 380,
"wires": []
}
]