# Parse Data from XML

**URL:** <https://discourse.nodered.org/t/parse-data-from-xml/7347>\
**Category:** General\
**Created:** [28 January 2019 22:07 UTC](https://discourse.nodered.org/t/parse-data-from-xml/7347 "2019-01-28T22:07:56Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![KevinPamu](https://avatars.discourse-cdn.com/v4/letter/k/ba9def/32.png) [@KevinPamu](https://discourse.nodered.org/u/KevinPamu)\
**Post date:** [28 January 2019 22:07 UTC](https://discourse.nodered.org/t/parse-data-from-xml/7347/1 "2019-01-28T22:07:57Z")

</div>

Hi,

I am still learning node-red, I was able to complete one part of the project recently thanks to all of your help. I now have another part of the project I am stuck on. I have a XML file that I needed to parse data from. I will attach the XML file to the question. I was wondering if there was a way I can use a particular node that would help me parse data from the XML file.

Specifically I needed the TenderType and Amount. Any help would be appreciated. Thank you in advance.

[incometest.txt](https://discourse.nodered.org/uploads/short-url/b34ulJuEJoVImKREmet2DRhCC6V.txt) (1.8 KB)

---

<div class="post-metadata">

**Author:** ![ukmoose](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ukmoose/32/13_2.png) [@ukmoose](https://discourse.nodered.org/u/ukmoose)\
**Post date:** [28 January 2019 22:10 UTC](https://discourse.nodered.org/t/parse-data-from-xml/7347/2 "2019-01-28T22:10:04Z")

</div>

Try the xml node that will convert from xml to a javascript object or the other way.

Use xml and then link it to a debug node

---

<div class="post-metadata">

**Author:** ![KevinPamu](https://avatars.discourse-cdn.com/v4/letter/k/ba9def/32.png) [@KevinPamu](https://discourse.nodered.org/u/KevinPamu)\
**Post date:** [28 January 2019 22:12 UTC](https://discourse.nodered.org/t/parse-data-from-xml/7347/3 "2019-01-28T22:12:38Z")

</div>

Was just trying that node, how would I access the particular value from the JS object? maybe from a function?

---

<div class="post-metadata">

**Author:** ![ukmoose](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ukmoose/32/13_2.png) [@ukmoose](https://discourse.nodered.org/u/ukmoose)\
**Post date:** [28 January 2019 22:15 UTC](https://discourse.nodered.org/t/parse-data-from-xml/7347/4 "2019-01-28T22:15:11Z")

</div>

you could use a function or a change node.

But use a debug node to take a look at the object and look at the “working with messages” page in the docs to see how useful the debug panel can be.

---

<div class="post-metadata">

**Author:** ![KevinPamu](https://avatars.discourse-cdn.com/v4/letter/k/ba9def/32.png) [@KevinPamu](https://discourse.nodered.org/u/KevinPamu)\
**Post date:** [28 January 2019 22:19 UTC](https://discourse.nodered.org/t/parse-data-from-xml/7347/5 "2019-01-28T22:19:42Z")

</div>

![4](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/a/a02b9cb2789d09973508695c99cd9724d77fe56a.jpeg)

That did help it convert it into a JavaScript Object. I tried to put in a function node in between and maybe access some of the values in the object. How would you suggest I do that? Syntax wise in the function node.

Thank you

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [28 January 2019 22:51 UTC](https://discourse.nodered.org/t/parse-data-from-xml/7347/6 "2019-01-28T22:51:39Z")

</div>

Hi @KevinPamu - as Mark mentioned, the [https://nodered.org/docs/user-guide/messages](https://nodered.org/docs/user-guide/messages) page in the docs tells you how you can use the Debug sidebar to identify the path to any element in the message - it can copy that path straight to your clipboard.

Once you have that you could do something like:

```auto
msg.payload = msg.<paste-the-path-from-debug-sidebar-here>;
return msg;

```

Or similarly using the Change node.

---

<div class="post-metadata">

**Author:** ![KevinPamu](https://avatars.discourse-cdn.com/v4/letter/k/ba9def/32.png) [@KevinPamu](https://discourse.nodered.org/u/KevinPamu)\
**Post date:** [28 January 2019 22:59 UTC](https://discourse.nodered.org/t/parse-data-from-xml/7347/7 "2019-01-28T22:59:59Z")

</div>

Thank you for the reply @knolleary I tried doing that and receive this message, "TypeError: Cannot read property 'Transaction' of undefined". Will keep trying to work with it. However, I will receive more than one message like that and I was wondering if there would be a way I can have a set syntax to get the values for every xml file.

 ![6](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/b/bb49f8884d376815b877b30f27075b62d8c12c1e.jpeg)

---

<div class="post-metadata">

**Author:** ![KevinPamu](https://avatars.discourse-cdn.com/v4/letter/k/ba9def/32.png) [@KevinPamu](https://discourse.nodered.org/u/KevinPamu)\
**Post date:** [29 January 2019 18:38 UTC](https://discourse.nodered.org/t/parse-data-from-xml/7347/8 "2019-01-29T18:38:19Z")

</div>

Thank you for the solution @knolleary @ukmoose . I have a follow up question, do you think there is a way I can find out the length of the TenderSummary array from the XML file?

---

<div class="post-metadata">

**Author:** ![ukmoose](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ukmoose/32/13_2.png) [@ukmoose](https://discourse.nodered.org/u/ukmoose)\
**Post date:** [29 January 2019 18:41 UTC](https://discourse.nodered.org/t/parse-data-from-xml/7347/9 "2019-01-29T18:41:44Z")

</div>

LMGTFY: [https://www.w3schools.com/jsref/jsref\_length\_array.asp](https://www.w3schools.com/jsref/jsref_length_array.asp)

---

<div class="post-metadata">

**Author:** ![fw\_scanav](https://avatars.discourse-cdn.com/v4/letter/f/8491ac/32.png) [@fw\_scanav](https://discourse.nodered.org/u/fw_scanav)\
**Post date:** [6 March 2019 12:03 UTC](https://discourse.nodered.org/t/parse-data-from-xml/7347/10 "2019-03-06T12:03:30Z")

</div>

Hello! I have a similar problem when i try to extract data from a specific object from a room scheduling server.  
"msg.payload.ArrayOfScreenOccasion.ScreenOccasion[0]"  
What I'm trying to do is that "ObjectName[0]" contains the name of the room which i will use to the filter the data "msg.payload.ArrayOfScreenOccasion.ScreenOccasion[0]" and send the data to a screen mounted outside the room. Inside the "ScreenOccasion[0]" contains the following:

- ObjectName[0] (Name of the room)
- StartDate[0] (format: 2019-03-06T09:00:00+01:00)
- EndDate[0] (format:2019-03-06T16:30:00+01:00)
- ExtraInfo[0].ScreenOccasionExtraInfo[0].TextValue[0] (Contains the booking description)
- ExtraInfo[0].ScreenOccasionExtraInfo[1].TextValue[0] (Contains the customer name)  
"msg.payload.ArrayOfScreenOccasion.ScreenOccasion[1]" is the next booking.  
all the bookings appears unsorted  
How do I extract the data and publish it to the right room?

---

<div class="post-metadata">

**Author:** ![ukmoose](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ukmoose/32/13_2.png) [@ukmoose](https://discourse.nodered.org/u/ukmoose)\
**Post date:** [6 March 2019 13:11 UTC](https://discourse.nodered.org/t/parse-data-from-xml/7347/11 "2019-03-06T13:11:19Z")

</div>

So you have an array of bookings as it says "msg.payload.ArrayOfScreenOccasion"

You could either use JSONata to filter the data or use an old fashioned function node and iterate through the array

---

<div class="post-metadata">

**Author:** ![fw\_scanav](https://avatars.discourse-cdn.com/v4/letter/f/8491ac/32.png) [@fw\_scanav](https://discourse.nodered.org/u/fw_scanav)\
**Post date:** [6 March 2019 13:35 UTC](https://discourse.nodered.org/t/parse-data-from-xml/7347/12 "2019-03-06T13:35:30Z")

</div>

OK. Do you have an example?  
The thing is that i have to publish the data to an another server which controls the panels outside the rooms via TCP/IP.

---

<div class="post-metadata">

**Author:** ![ukmoose](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ukmoose/32/13_2.png) [@ukmoose](https://discourse.nodered.org/u/ukmoose)\
**Post date:** [6 March 2019 13:37 UTC](https://discourse.nodered.org/t/parse-data-from-xml/7347/13 "2019-03-06T13:37:41Z")

</div>

No but there’s an exerciser on the jsonata website where you can learn all about it

---

<div class="post-metadata">

**Author:** ![fw\_scanav](https://avatars.discourse-cdn.com/v4/letter/f/8491ac/32.png) [@fw\_scanav](https://discourse.nodered.org/u/fw_scanav)\
**Post date:** [6 March 2019 13:47 UTC](https://discourse.nodered.org/t/parse-data-from-xml/7347/14 "2019-03-06T13:47:19Z")

</div>

Ok. Do you have a link to the sonata website? 🙂

---

<div class="post-metadata">

**Author:** ![ukmoose](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ukmoose/32/13_2.png) [@ukmoose](https://discourse.nodered.org/u/ukmoose)\
**Post date:** [6 March 2019 13:57 UTC](https://discourse.nodered.org/t/parse-data-from-xml/7347/15 "2019-03-06T13:57:00Z")

</div>

i’m sure if you google jsonata you’ll find it

---

<div class="post-metadata">

**Author:** ![fw\_scanav](https://avatars.discourse-cdn.com/v4/letter/f/8491ac/32.png) [@fw\_scanav](https://discourse.nodered.org/u/fw_scanav)\
**Post date:** [6 March 2019 14:04 UTC](https://discourse.nodered.org/t/parse-data-from-xml/7347/16 "2019-03-06T14:04:38Z")

</div>

Ok. Thanks! I saw your post saying "sonata" before you edit it.
