Browse code

add parse options

devnewton authored on 06/09/2017 14:13:45
Showing 2 changed files
... ...
@@ -19,6 +19,19 @@
19 19
         </select>
20 20
     </div>
21 21
     <div class="form-row">
22
+        <input id="node-input-xmlMode" type="checkbox" style="width: auto; vertical-align: top;">
23
+        <label for="node-input-xmlMode" style="width: auto;">XML mode</label>
24
+        <input id="node-input-decodeEntities" type="checkbox" style="width: auto; vertical-align: top;">
25
+        <label for="node-input-decodeEntities" style="width: auto;">Decode entities</label>
26
+        <input id="node-input-lowerCaseTags" type="checkbox" style="width: auto; vertical-align: top;">
27
+        <label for="node-input-lowerCaseTags" style="width: auto;">Lower case tags</label>
28
+        <input id="node-input-lowerCaseAttributeNames" type="checkbox" style="width: auto; vertical-align: top;">
29
+        <label for="node-input-lowerCaseAttributeNames" style="width: auto;">Lower attribute names</label>
30
+        <input id="node-input-recognizeCDATA" type="checkbox" style="width: auto; vertical-align: top;">
31
+        <label for="node-input-recognizeCDATA" style="width: auto;">Recognize CDATA</label>
32
+    </div>
33
+    
34
+    <div class="form-row">
22 35
         <div id="node-input-mapping-container-div" style="border-radius: 5px; height: 320px; padding: 5px; border: 1px solid #ccc; overflow-y:scroll;">
23 36
         <ol id="node-input-mapping-container" style=" list-style-type:none; margin: 0;">
24 37
         </ol>
... ...
@@ -62,7 +75,13 @@
62 75
             tag: {value: ""},
63 76
             ret: {value: "html"},
64 77
             as: {value: "single"},
65
-            map: {value:[{search:"",replace:"", ret: "html", attr: ""}]}
78
+            map: {value:[{search:"",replace:"", ret: "html", attr: ""}]},
79
+            xmlMode: {value: false},
80
+            decodeEntities: {value: false},
81
+            lowerCaseTags: {value: false},
82
+            lowerCaseAttributeNames: {value: false},
83
+            recognizeCDATA: {value: false},
84
+            recognizeSelfClosing: {value: false}
66 85
         },
67 86
         inputs: 1,
68 87
         outputs: 1,
... ...
@@ -7,6 +7,14 @@ module.exports = function (RED) {
7 7
         this.ret = n.ret || "html";
8 8
         this.as = n.as || "single";
9 9
         this.map = n.map || [];
10
+        this.parseOptions = {
11
+            xmlMode: n.xmlMode,
12
+            decodeEntities: n.decodeEntities,
13
+            lowerCaseTags: n.lowerCaseTags,
14
+            lowerCaseAttributeNames: n.lowerCaseAttributeNames,
15
+            recognizeCDATA: n.recognizeCDATA,
16
+            recognizeSelfClosing: n.recognizeSelfClosing
17
+        };
10 18
         var node = this;
11 19
         this.on("input", function (msg) {
12 20
             if (msg.hasOwnProperty("payload")) {
... ...
@@ -15,7 +23,7 @@ module.exports = function (RED) {
15 23
                     tag = node.tag || msg.select;
16 24
                 }
17 25
                 try {
18
-                    var $ = cheerio.load(msg.payload);
26
+                    var $ = cheerio.load(msg.payload, node.parseOptions);
19 27
                     var payloads = [];
20 28
                     $(tag).each(function () {
21 29
                         var payload = null;
... ...
@@ -65,7 +73,7 @@ module.exports = function (RED) {
65 73
                 }
66 74
             } else {
67 75
                 node.send(msg);
68
-            } // If no payload - just pass it on.
76
+            }
69 77
         });
70 78
     }
71 79
     RED.nodes.registerType("cheerio", CheerioNode);