node-red-contrib-collector

715 views
Skip to first unread message

Ram

unread,
Nov 16, 2016, 6:47:19 AM11/16/16
to Node-RED
How do i get rid of the highlighted items using 

node-red-contrib-collector


Screenshot on left shows the highlighted extra chunk that needs to be removed.



steve rickus

unread,
Nov 16, 2016, 9:55:51 AM11/16/16
to Node-RED
The "XML" on the left is not even valid -- was the output from another node? If so, the author should probably be notified...

Assuming that the text on the left is a string that you received in a msg.payload, you can use a function node to remove those strings, using a regex such as:

msg.payload = msg.payload.replace(/<\/node .*+>/g, "</node>");
return msg;

I tried using the XML node to convert the "string" on the left to actual XML, but it throws an exception, as it probably should. Of course, it would be nice to have an option on the XML node to ignore invalid text (like using a lenient parser). But I guess that would just turn it into an xml-lint node.
--
Steve

Ram

unread,
Nov 16, 2016, 10:34:43 AM11/16/16
to Node-RED
Hi,
Yes, the output on the left has errors and when I tried validating with XML validator, it threw me errors. The right side version is the fixed version which is manually done. I've informed the author.

When I tried your function script, I get the following error:

TypeError: msg.payload.replace is not a function


Also, the node threw me errors and I had to modify it to 
msg.payload = msg.payload.replace(/<\/node .*>/g, "</node>");
return msg;

steve rickus

unread,
Nov 16, 2016, 1:26:02 PM11/16/16
to Node-RED
If the replace function is undefined, then msg.payload is NOT a string -- which is why I asked that first.

Ah, sorry about the typo -- instead of the '+' it should have been a '?'. That keeps the expression from being greedy and grabbing more than just the characters between the angle brackets.

Here is a better regex to use: the character class '[^>]' matches any character that is NOT a closing angle bracket.

msg.payload = msg.payload.replace(/<\/node [^>]*>/g, "</node>");
return msg;

Ram

unread,
Nov 16, 2016, 11:01:01 PM11/16/16
to Node-RED
This actually fixed my issue. Thanks a lot. Previously, I connected to the wrong node and hence the errors.
Reply all
Reply to author
Forward
0 new messages