String/Object message handling

Hi,

Iv`e reached the end of my string here with a get/http return message from a IP camera where I will extract some data to make a download link. The request message returns a string with:

?xml version="1.0"?>

<root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://www.axis.com/vapix/http_cgi/recording/list1.xsd">

  <recordings totalnumberofrecordings="9" numberofrecordings="9">    <recording diskid="SD_DISK" recordingid="20201225_124627_148A_ACCC8E9C6AC1" starttime="2020-12-25T11:46:27.875685Z" starttimelocal="2020-12-25T12:46:27.875685+01:00" stoptime="2020-12-25T19:11:56.181874Z" stoptimelocal="2020-12-25T20:11:56.181874+01:00" recordingtype="continuous" eventid="continuous_0" eventtrigger="continuous" recordingstatus="recording" source="1" locked="No">      <video mimetype="video/x-h264" width="1920" height="1080" framerate="30:1" resolution="1920x1080"/>
    </recording>
    <recording diskid="SD_DISK" recordingid="20201129_213935_328F_ACCC8E9C6AC1" starttime="2020-11-29T20:39:35.215442Z" starttimelocal="2020-11-29T21:39:35.215442+01:00" stoptime="2020-11-29T20:43:39.712775Z" stoptimelocal="2020-11-29T21:43:39.712775+01:0....

And so it continues depending on the number of recordings. Im trying to extract all data between recordingid=< and >recording type , seperated so I can push them on to a UI list where each recording will push the needed data via a function and get request.

Is moving it from a string to an array and digging into indexOf() functions the correct path?

Since the reply from your Http request is an XML you can use the XML node to parse the payload into a JS object. After that pickup the information you need with the Copy path icon .

image
.

.

Example :

[{"id":"76977231.73b1fc","type":"inject","z":"32cacc4b.b57a94","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":400,"y":320,"wires":[["5221803c.f899a8"]]},{"id":"23c44139.8d1a7e","type":"xml","z":"32cacc4b.b57a94","name":"","property":"payload","attr":"","chr":"","x":370,"y":440,"wires":[["b84fbcdc.80ac3"]]},{"id":"b84fbcdc.80ac3","type":"debug","z":"32cacc4b.b57a94","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":370,"y":500,"wires":[]},{"id":"5221803c.f899a8","type":"function","z":"32cacc4b.b57a94","name":"","func":"msg.payload = ` \n<?xml version=\"1.0\"?>\n<root xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"http://www.axis.com/vapix/http_cgi/recording/list1.xsd\">\n<recordings totalnumberofrecordings=\"9\" numberofrecordings=\"9\">    \n<recording diskid=\"SD_DISK\" recordingid=\"20201225_124627_148A_ACCC8E9C6AC1\" starttime=\"2020-12-25T11:46:27.875685Z\" starttimelocal=\"2020-12-25T12:46:27.875685+01:00\" stoptime=\"2020-12-25T19:11:56.181874Z\" stoptimelocal=\"2020-12-25T20:11:56.181874+01:00\" recordingtype=\"continuous\" eventid=\"continuous_0\" eventtrigger=\"continuous\" recordingstatus=\"recording\" source=\"1\" locked=\"No\">      \n<video mimetype=\"video/x-h264\" width=\"1920\" height=\"1080\" framerate=\"30:1\" resolution=\"1920x1080\"/>\n</recording>\n<recording diskid=\"SD_DISK\" recordingid=\"20201129_213935_328F_ACCC8E9C6AC1\" starttime=\"2020-11-29T20:39:35.215442Z\" starttimelocal=\"2020-11-29T21:39:35.215442+01:00\" stoptime=\"2020-11-29T20:43:39.712775Z\" stoptimelocal=\"2020-11-29T21:43:39.712775+01:00\" recordingtype=\"continuous\" eventid=\"continuous_0\" eventtrigger=\"continuous\" recordingstatus=\"recording\" source=\"2\" locked=\"No\">\n<video mimetype=\"video/x-h264\" width=\"1920\" height=\"1080\" framerate=\"30:1\" resolution=\"1920x1080\"/>\n</recording>\n</recordings>\n</root>\n`\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":380,"y":380,"wires":[["23c44139.8d1a7e"]]}]

Brilliant, that got me to where I needed, many thanks!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.