# XML value of all data

**URL:** <https://discourse.nodered.org/t/xml-value-of-all-data/48937>\
**Category:** General\
**Created:** [26 July 2021 19:45 UTC](https://discourse.nodered.org/t/xml-value-of-all-data/48937 "2021-07-26T19:45:34Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![madmax](https://avatars.discourse-cdn.com/v4/letter/m/8baadc/32.png) [@madmax](https://discourse.nodered.org/u/madmax)\
**Post date:** [26 July 2021 19:45 UTC](https://discourse.nodered.org/t/xml-value-of-all-data/48937/1 "2021-07-26T19:45:34Z")

</div>

Hello!

I have an XML file.

How can I filter this value of all data?

payload.HRC\_STOCK.PRODUCT [0]

[https://www.hrcdistribution.com/xml/xml\_feed\_stock.php?c=8407](https://www.hrcdistribution.com/xml/xml_feed_stock.php?c=8407)

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [26 July 2021 20:08 UTC](https://discourse.nodered.org/t/xml-value-of-all-data/48937/2 "2021-07-26T20:08:48Z")

</div>

what bit are you stuck on

- getting the XML from the web URL?
- converting the XML to JS object?
- getting the first element `payload.HRC_STOCK.PRODUCT[0]`?

* * *

If you want to access `payload.HRC_STOCK.PRODUCT[0]` in a function then remember to add `msg.` e.g. `msg.payload.HRC_STOCK.PRODUCT[0]`

There’s a great page in the docs 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)

[https://nodered.org/docs/user-guide/messages](https://nodered.org/docs/user-guide/messages)

---

<div class="post-metadata">

**Author:** ![madmax](https://avatars.discourse-cdn.com/v4/letter/m/8baadc/32.png) [@madmax](https://discourse.nodered.org/u/madmax)\
**Post date:** [26 July 2021 20:19 UTC](https://discourse.nodered.org/t/xml-value-of-all-data/48937/3 "2021-07-26T20:19:24Z")

</div>

Hello!

Many thanks for the answer.

I would like to have all the data from the file in an object.

But if I enter the following in the function, I only get one record back.

msg.payload = msg.payload.HRC\_STOCK.PRODUCT [0]  
return msg;

I can do that that everyone comes?

It should look like this with my CSV file  
 ![Bildschirmfoto 2021-07-26 um 22.18.33](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/7/a7f1e9e482e2b58d867380db33ae1f73b8081768.png)

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [26 July 2021 20:24 UTC](https://discourse.nodered.org/t/xml-value-of-all-data/48937/4 "2021-07-26T20:24:38Z")

</div>

> [@madmax](#):
>
> I would like to have all the data from the file in an object.
> 
> But if I enter the following in the function, I only get one record back.
> 
> msg.payload = msg.payload.HRC\_STOCK.PRODUCT [0]  
> return msg;

Well, thats because you are only taking the first element.

If you don't do that, you will have all data in `msg.payload.HRC_STOCK.PRODUCT` where you can access the first object in `[0]` and the 2nd in `[1]` etc

  

If you want the ditch the `HRC_STOCK.PRODUCT` properties then simply assign that to the msg.payload...

```auto
msg.payload = msg.payload.HRC_STOCK.PRODUCT;
return msg;

```

---

<div class="post-metadata">

**Author:** ![madmax](https://avatars.discourse-cdn.com/v4/letter/m/8baadc/32.png) [@madmax](https://discourse.nodered.org/u/madmax)\
**Post date:** [26 July 2021 20:31 UTC](https://discourse.nodered.org/t/xml-value-of-all-data/48937/5 "2021-07-26T20:31:33Z")

</div>

> [@Steve-Mcl](#):
>
> Well, thats because you are only taking the first element.
> 
> If you don't do that, you will have all data in `msg.payload.HRC_STOCK.PRODUCT` where you can access the first object in `[0]` and the 2nd in `[1]` etc
> 
> If you want the ditch the `HRC_STOCK.PRODUCT` properties then simply assign that to the msg.payload...

Thanks for the reply

But there has to be a way to take all the data.

I can't make a command for every line. That's 7000 lines.

Is it possible to convert it to a CSV file?

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [26 July 2021 20:37 UTC](https://discourse.nodered.org/t/xml-value-of-all-data/48937/6 "2021-07-26T20:37:42Z")

</div>

> [@madmax](#):
>
> Is it possible to convert it to a CSV file?

Yes, but why? what are you doing with the data? Must you convert to CSV? CSV is so 1990! What is the ultimate goal for this data?

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [26 July 2021 20:40 UTC](https://discourse.nodered.org/t/xml-value-of-all-data/48937/7 "2021-07-26T20:40:12Z")

</div>

If you must...  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/4/a49260253260f771f562cff09f66213d90a5d8a5.png)

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/8/58ca2873549b4dcb17b8cc0da9c49d5dd290b33c.png)

```auto
[{"id":"a7fd9025.796f9","type":"inject","z":"1bd2b382.4dd4f4","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":474,"y":1168,"wires":[["1793ba5a.ba2bc6"]]},{"id":"1793ba5a.ba2bc6","type":"http request","z":"1bd2b382.4dd4f4","name":"","method":"GET","ret":"txt","paytoqs":"ignore","url":"https://www.hrcdistribution.com/xml/xml_feed_stock.php?c=8407","tls":"","persist":false,"proxy":"","authType":"","x":646,"y":1168,"wires":[["49fde8c4.ea29b8"]]},{"id":"49fde8c4.ea29b8","type":"xml","z":"1bd2b382.4dd4f4","name":"","property":"payload","attr":"","chr":"","x":832,"y":1168,"wires":[["cab07671.087e38"]]},{"id":"cab07671.087e38","type":"function","z":"1bd2b382.4dd4f4","name":"","func":"var data = msg.payload.HRC_STOCK.PRODUCT;\n\nmsg.payload = data.map(e => {\n return { \n \"ID\": Number(e.ID[0]),\n \"REF\": e.REF[0],\n \"STOCK\": Number(e.STOCK[0]),\n }\n});\n\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":970,"y":1168,"wires":[["bfc215a.db2aee8","8bb8fd56.a2ad5"]]},{"id":"bfc215a.db2aee8","type":"debug","z":"1bd2b382.4dd4f4","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1142,"y":1168,"wires":[]},{"id":"8bb8fd56.a2ad5","type":"csv","z":"1bd2b382.4dd4f4","name":"","sep":",","hdrin":"","hdrout":"none","multi":"one","ret":"\\n","temp":"","skip":"0","strings":true,"include_empty_strings":"","include_null_values":"","x":1024,"y":1232,"wires":[["ab242884.5e4f08"]]},{"id":"ab242884.5e4f08","type":"debug","z":"1bd2b382.4dd4f4","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1174,"y":1232,"wires":[]}]

```

---

<div class="post-metadata">

**Author:** ![madmax](https://avatars.discourse-cdn.com/v4/letter/m/8baadc/32.png) [@madmax](https://discourse.nodered.org/u/madmax)\
**Post date:** [26 July 2021 20:42 UTC](https://discourse.nodered.org/t/xml-value-of-all-data/48937/8 "2021-07-26T20:42:16Z")

</div>

> [@Steve-Mcl](#):
>
> s, but why? what are you doing with the data? Must you convert to CSV? CSV is so 1990! What is the ultimate goal for this data?

Hello!

the goal is to add up all payload.HRC\_STOCK.PRODUCT [0] .STOCK [0] values.

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [26 July 2021 20:54 UTC](https://discourse.nodered.org/t/xml-value-of-all-data/48937/9 "2021-07-26T20:54:01Z")

</div>

Then CSV is not what you want...

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

```auto
[{"id":"a7fd9025.796f9","type":"inject","z":"1bd2b382.4dd4f4","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":492,"y":1168,"wires":[["1793ba5a.ba2bc6"]]},{"id":"1793ba5a.ba2bc6","type":"http request","z":"1bd2b382.4dd4f4","name":"","method":"GET","ret":"txt","paytoqs":"ignore","url":"https://www.hrcdistribution.com/xml/xml_feed_stock.php?c=8407","tls":"","persist":false,"proxy":"","authType":"","x":662,"y":1168,"wires":[["49fde8c4.ea29b8"]]},{"id":"49fde8c4.ea29b8","type":"xml","z":"1bd2b382.4dd4f4","name":"","property":"payload","attr":"","chr":"","x":818,"y":1168,"wires":[["cab07671.087e38"]]},{"id":"cab07671.087e38","type":"function","z":"1bd2b382.4dd4f4","name":"Sum of STOCK","func":"msg.payload = msg.payload.HRC_STOCK.PRODUCT.reduce((a,b) => {\n return a + Number(b.STOCK[0]);\n}, 0)\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":990,"y":1168,"wires":[["bfc215a.db2aee8"]]},{"id":"bfc215a.db2aee8","type":"debug","z":"1bd2b382.4dd4f4","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":1174,"y":1168,"wires":[]}]

```

---

<div class="post-metadata">

**Author:** ![madmax](https://avatars.discourse-cdn.com/v4/letter/m/8baadc/32.png) [@madmax](https://discourse.nodered.org/u/madmax)\
**Post date:** [27 July 2021 04:56 UTC](https://discourse.nodered.org/t/xml-value-of-all-data/48937/10 "2021-07-27T04:56:26Z")

</div>

> [@Steve-Mcl](#):
>
> nt...

Great that's exactly what I wanted. Thanks alot.

---

<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:** [10 August 2021 04:56 UTC](https://discourse.nodered.org/t/xml-value-of-all-data/48937/11 "2021-08-10T04:56:33Z")

</div>

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