# New to XML data

**URL:** <https://discourse.nodered.org/t/new-to-xml-data/69194>\
**Category:** General\
**Created:** [18 October 2022 08:26 UTC](https://discourse.nodered.org/t/new-to-xml-data/69194 "2022-10-18T08:26:42Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kaij3](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/kaij3/32/60268_2.png) [@Kaij3](https://discourse.nodered.org/u/Kaij3)\
**Post date:** [18 October 2022 08:26 UTC](https://discourse.nodered.org/t/new-to-xml-data/69194/1 "2022-10-18T08:26:42Z")

</div>

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.

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/1/319e5d2cf013c6685d5bf556541e484b0c06be70.png)

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

```auto
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!

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [18 October 2022 08:36 UTC](https://discourse.nodered.org/t/new-to-xml-data/69194/2 "2022-10-18T08:36:42Z")

</div>

> [@Kaij3](#):
>
> 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.

Not sure I would class the alternatives as "simpler" 🙂

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](https://stackoverflow.com/questions/15642494/find-property-by-name-in-a-deep-object)

---

<div class="post-metadata">

**Author:** ![Kaij3](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/kaij3/32/60268_2.png) [@Kaij3](https://discourse.nodered.org/u/Kaij3)\
**Post date:** [18 October 2022 08:44 UTC](https://discourse.nodered.org/t/new-to-xml-data/69194/3 "2022-10-18T08:44:48Z")

</div>

@TotallyInformation ,

Thanks for the suggestion, no worries!

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [18 October 2022 08:48 UTC](https://discourse.nodered.org/t/new-to-xml-data/69194/4 "2022-10-18T08:48:12Z")

</div>

> [@Kaij3](#):
>
> is there a simpler way to get the first data, which is in a different object and under Serial Number.

What do you mean by 'a different object'?

---

<div class="post-metadata">

**Author:** ![Kaij3](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/kaij3/32/60268_2.png) [@Kaij3](https://discourse.nodered.org/u/Kaij3)\
**Post date:** [18 October 2022 09:01 UTC](https://discourse.nodered.org/t/new-to-xml-data/69194/5 "2022-10-18T09:01:32Z")

</div>

@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;`

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/b/bbf16e70eb16590a0862cd76f3f7cc0561a5d823.png)

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

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [18 October 2022 09:30 UTC](https://discourse.nodered.org/t/new-to-xml-data/69194/6 "2022-10-18T09:30:06Z")

</div>

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](https://nodered.org/docs/user-guide/messages)) 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](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/d/bd1f333a9e043b061b39917c328b0094d3e52d30.gif)

---

<div class="post-metadata">

**Author:** ![Kaij3](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/kaij3/32/60268_2.png) [@Kaij3](https://discourse.nodered.org/u/Kaij3)\
**Post date:** [18 October 2022 09:36 UTC](https://discourse.nodered.org/t/new-to-xml-data/69194/7 "2022-10-18T09:36:59Z")

</div>

@Colin

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

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [17 December 2022 09:37 UTC](https://discourse.nodered.org/t/new-to-xml-data/69194/8 "2022-12-17T09:37:58Z")

</div>

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