New to XML data

Hello all!,

Recently, I've been using MT Connect to retrieve data from one of the equipment, and after using an XML node, I was able to retrieve the data shown at the bottom of the image.

However, in order to take the first item such as for example "5942" , i need to through a long process such as writing a code like this

const data = msg.payload.MTConnectStreams.Streams[0].DeviceStream[0].ComponentStream[0].Events[0].SerialNumber[0]._
msg.payload = Number(data);
return msg;

So I am here asking, is there a simpler way to get the first data, which is in a different object and under Serial Number.

Thanks all!

Not sure I would class the alternatives as "simpler" :slight_smile:

However, you are using JavaScript and there will always be multiple ways of achieving the outcome.

You might actually be able to do it fairly easily with JSONata but I've not had morning coffee's yet and really should be working so no time to investigate I'm afraid.

Otherwise, you might find a usable solution in here:

javascript - Find property by name in a deep object - Stack Overflow

@TotallyInformation ,

Thanks for the suggestion, no worries!

What do you mean by 'a different object'?

@Colin

Hi , what I meant was that in order to get the number 5429, in the function, the code is written like this.

const data = msg.payload.MTConnectStreams.Streams[0].DeviceStream[0].ComponentStream[0].Events[0].SerialNumber[0]._ msg.payload = Number(data); return msg;

But for actuator state is it under a different object under Events which holds an array of objects ?

I am sorry if i don't make sense , I'm still new to this

It is probably possible, but it would take longer to work out how than just writing them out. Assuming there are not a lot of different paths to determine. For coding it I presume you have seen this canned reply, which lets you pick up the paths from the debug pane:

There’s a great page in the docs (Working with messages : Node-RED) that will explain how to use the debug panel to find the right path to any data item.

Pay particular attention to the part about the buttons that appear under your mouse pointer when you over hover a debug message property in the sidebar.

BX00Cy7yHi

@Colin

Hahaha , that's what i thought too , thank you for the suggestion sir