Join payload and split

Hi.
I have a sliced xml that arrives in serveral payloads in string format. I want to listen on the payloads and have an output that starts with and ends with from a payload to a payload that arrives later so i can convert it back to xml with a valid start and end tag.

Hard to explain.
i attach a picture of the payloads so maybe you understand what i mean.

/niclas

here is an example of a split xml joined as a string.
the 3 injects hold the 3 xml parts only when last one is sent does the xml get passed on. Only if parts are in order does this work

[{"id":"a8c11fb9.9055","type":"inject","z":"8d22ae29.7df6d","name":"part 1","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"<CATALOG><CD><TITLE>Empire Burlesque</TITLE><ARTIST>Bob Dylan</ARTIST><COUNTRY>USA</COUNTRY><COMPANY>Columbia</COMPANY><PRICE>10.90</PRICE><YEAR>1985</YEAR></CD><CD><TITLE>Hide your heart</TITLE><ARTIST>Bonnie Tyler</ARTIST><COUNTRY>UK</COUNTRY><COMPANY>CBS Records</COMPANY><PRICE>9.90</PRICE><YEAR>1988</YEAR></CD>","payloadType":"str","x":200,"y":1720,"wires":[["76e122df.8ed87c"]]},{"id":"76e122df.8ed87c","type":"function","z":"8d22ae29.7df6d","name":"","func":"if (msg.payload.substr(-10) ===  \"</CATALOG>\"){\n    msg.complete = true\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":390,"y":1800,"wires":[["d97c11aa.2c90b8"]]},{"id":"d97c11aa.2c90b8","type":"join","z":"8d22ae29.7df6d","name":"","mode":"custom","build":"string","property":"payload","propertyType":"msg","key":"topic","joiner":"","joinerType":"str","accumulate":false,"timeout":"","count":"","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":590,"y":1800,"wires":[["2da22367.b6999c"]]},{"id":"c815e9db.a393f8","type":"inject","z":"8d22ae29.7df6d","name":"part 2","props":[{"p":"payload"},{"p":"topic","v":"$moment().tz(\"Euroupe/London\")","vt":"jsonata"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"<CD><TITLE>Still got the blues</TITLE><ARTIST>Gary Moore</ARTIST><COUNTRY>UK</COUNTRY><COMPANY>Virgin records</COMPANY><PRICE>10.20</PRICE><YEAR>1990</YEAR></CD><CD><TITLE>Eros</TITLE><ARTIST>Eros Ramazzotti</ARTIST><COUNTRY>EU</COUNTRY><COMPANY>BMG</COMPANY><PRICE>9.90</PRICE><YEAR>1997</YEAR></CD>","payloadType":"str","x":170,"y":1800,"wires":[["76e122df.8ed87c"]]},{"id":"49f73435.47a794","type":"inject","z":"8d22ae29.7df6d","name":"part 3","props":[{"p":"payload"},{"p":"topic","v":"$toMillis($now())","vt":"jsonata"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"<CD><TITLE>One night only</TITLE><ARTIST>Bee Gees</ARTIST><COUNTRY>UK</COUNTRY><COMPANY>Polydor</COMPANY><PRICE>10.90</PRICE><YEAR>1998</YEAR></CD><CD><TITLE>Sylvias Mother</TITLE><ARTIST>Dr.Hook</ARTIST><COUNTRY>UK</COUNTRY><COMPANY>CBS</COMPANY><PRICE>8.10</PRICE><YEAR>1973</YEAR></CD></CATALOG>","payloadType":"str","x":190,"y":1880,"wires":[["76e122df.8ed87c"]]},{"id":"2da22367.b6999c","type":"debug","z":"8d22ae29.7df6d","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":750,"y":1800,"wires":[]}]

Hi.

I your example the first xml is starting with
But in my case the xml can start with anywhere. so it must start to search for and then set msg.complete when it finds
Can I somehow even declare the start tag also?

/regards Niclas

Without understanding exactly how yor xml is sent its difficult to say,.
Can you give a slimmed down representation of the recived payloads?

Maybe something like this will work.

[{"id":"a8c11fb9.9055","type":"inject","z":"8d22ae29.7df6d","name":"part 1","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"<CD><TITLE>One night only</TITLE><ARTIST>Bee Gees</ARTIST><COUNTRY>UK</COUNTRY><COMPANY>Polydor</COMPANY><PRICE>10.90</PRICE><YEAR>1998</YEAR></CD><CD><TITLE>Sylvias Mother</TITLE><ARTIST>Dr.Hook</ARTIST><COUNTRY>UK</COUNTRY><COMPANY>CBS</COMPANY><PRICE>8.10</PRICE><YEAR>1973</YEAR></CD></CATALOG><CATALOG><CD><TITLE>Empire Burlesque</TITLE><ARTIST>Bob Dylan</ARTIST><COUNTRY>USA</COUNTRY><COMPANY>Columbia</COMPANY><PRICE>10.90</PRICE><YEAR>1985</YEAR></CD><CD><TITLE>Hide your heart</TITLE><ARTIST>Bonnie Tyler</ARTIST><COUNTRY>UK</COUNTRY><COMPANY>CBS Records</COMPANY><PRICE>9.90</PRICE><YEAR>1988</YEAR></CD>","payloadType":"str","x":200,"y":1720,"wires":[["76e122df.8ed87c"]]},{"id":"76e122df.8ed87c","type":"function","z":"8d22ae29.7df6d","name":"","func":"let tag = \"CATALOG\"\nlet splitStart = msg.payload.split(\"<\"+tag+\">\");\nif (splitStart.length > 1) {\n    msg.payload = (context.get(\"splitStart\") || \"\")+splitStart[0];\n    context.set(\"splitStart\", \"<\"+tag+\">\"+splitStart[1]);\n    msg.complete = true\n}else{\n    msg.payload = (context.get(\"splitStart\") || \"\")+msg.payload;\n    context.set(\"splitStart\", \"\");\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":390,"y":1800,"wires":[["d97c11aa.2c90b8"]]},{"id":"c815e9db.a393f8","type":"inject","z":"8d22ae29.7df6d","name":"part 2","props":[{"p":"payload"},{"p":"topic","v":"$moment().tz(\"Euroupe/London\")","vt":"jsonata"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"<CD><TITLE>Still got the blues</TITLE><ARTIST>Gary Moore</ARTIST><COUNTRY>UK</COUNTRY><COMPANY>Virgin records</COMPANY><PRICE>10.20</PRICE><YEAR>1990</YEAR></CD><CD><TITLE>Eros</TITLE><ARTIST>Eros Ramazzotti</ARTIST><COUNTRY>EU</COUNTRY><COMPANY>BMG</COMPANY><PRICE>9.90</PRICE><YEAR>1997</YEAR></CD>","payloadType":"str","x":170,"y":1800,"wires":[["76e122df.8ed87c"]]},{"id":"d97c11aa.2c90b8","type":"join","z":"8d22ae29.7df6d","name":"","mode":"custom","build":"string","property":"payload","propertyType":"msg","key":"topic","joiner":"","joinerType":"str","accumulate":false,"timeout":"","count":"","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":550,"y":1800,"wires":[["2da22367.b6999c"]]},{"id":"2da22367.b6999c","type":"debug","z":"8d22ae29.7df6d","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"$substring(payload, 0, 11) & $substring(payload,-11)","statusType":"jsonata","x":710,"y":1800,"wires":[]}]

Hi .

I have tried a lot with your function node. But i don´t really understand all of the code in it.
I will attach a nobe example that i did that almost works. But sometimes it don´t work and i really don´t know why?

The picture i attach from the debug is using my example code. Maybe it´s easier to understand what i trying to accomplish.

Best regards Niiclas

[{"id":"9a851d64.7e405","type":"function","z":"85cbf67a.52f0a8","name":"utf8","func":"msg.payload = msg.payload.toString('utf8');\nreturn msg;","outputs":1,"noerr":0,"x":410,"y":380,"wires":[["4c1e2f23.08b8c","61cba11f.399a8"]]},{"id":"4c1e2f23.08b8c","type":"split","z":"85cbf67a.52f0a8","name":"","splt":"<event id=","spltType":"str","arraySplt":"2","arraySpltType":"len","stream":false,"addname":"","x":190,"y":420,"wires":[["b535b318.12c06"]]},{"id":"b535b318.12c06","type":"function","z":"85cbf67a.52f0a8","name":"","func":"msg.payload = \"<event id=\"+msg.payload\nreturn msg;","outputs":1,"noerr":0,"x":310,"y":420,"wires":[["1367e5d5.84a2ca"]]},{"id":"1367e5d5.84a2ca","type":"function","z":"85cbf67a.52f0a8","name":"","func":"if (msg.payload ===  \"</event>\"){\n    msg.complete = true\n}\nreturn msg;","outputs":1,"noerr":0,"x":430,"y":420,"wires":[["f7973ca3.92db5"]]},{"id":"f7973ca3.92db5","type":"xml","z":"85cbf67a.52f0a8","name":"","property":"payload","attr":"","chr":"","x":630,"y":440,"wires":[["e980bc1a.f6ad9"]]}]

/regards Niclas