# XML Manipulation and searching

**URL:** <https://discourse.nodered.org/t/xml-manipulation-and-searching/83273>\
**Category:** General\
**Created:** [29 November 2023 07:15 UTC](https://discourse.nodered.org/t/xml-manipulation-and-searching/83273 "2023-11-29T07:15:01Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![leftymuller](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/leftymuller/32/102326_2.png) [@leftymuller](https://discourse.nodered.org/u/leftymuller)\
**Post date:** [29 November 2023 07:15 UTC](https://discourse.nodered.org/t/xml-manipulation-and-searching/83273/1 "2023-11-29T07:15:02Z")

</div>

G'Day Peoples,

Im a Bit of a Noob with XML and it turns out just doing some work with XML and an web API

Is there a way of searching XML for example, So if the location of the value, in this case "Printing Status" is searchable ?

msg.payload = msg.payload.jobs.job[0].sections[0].section[3].custom\_fields[0].custom\_field[4].value[0]

something like msg.payload.jobs.job[0]['Printing Status"][0]

That way if the XML structure changes it doesnt break

here is the debug xml structure

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

Unfortunately I cant post the flow as it has API keys in it

Also is there an easy way to show all wildcards for example

msg.payload.jobs.job[\*].status[0]

So it returns all job ticket numbers from the xml ?

Any Help is appreciated!

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [29 November 2023 07:32 UTC](https://discourse.nodered.org/t/xml-manipulation-and-searching/83273/2 "2023-11-29T07:32:07Z")

</div>

What you show is not xml. Looks like you have passed it through a xml node and it has been converted to a Javascript object.

You can seach the Object with a function node using Javascript functions e.g. find() or filter(). Or you can use JSONata in a change node. JSONata is great for wildcards, but most find it confusing syntactically.

Would provide an example but you have not given an example input and output in a form that is copyable.

---

<div class="post-metadata">

**Author:** ![leftymuller](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/leftymuller/32/102326_2.png) [@leftymuller](https://discourse.nodered.org/u/leftymuller)\
**Post date:** [29 November 2023 08:37 UTC](https://discourse.nodered.org/t/xml-manipulation-and-searching/83273/3 "2023-11-29T08:37:17Z")

</div>

Thanks for the replay

This is whats coming from the API without the xml node.

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/3/53b4289d9e621334b521fde1e40a03f1131e8668.jpeg)

Do I leave as is and use JSONata?

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [29 November 2023 08:39 UTC](https://discourse.nodered.org/t/xml-manipulation-and-searching/83273/4 "2023-11-29T08:39:36Z")

</div>

No you convert the xml to a Javascript Object, as you showed in first post. Then use JSONata expression to select the info you want.

---

<div class="post-metadata">

**Author:** ![leftymuller](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/leftymuller/32/102326_2.png) [@leftymuller](https://discourse.nodered.org/u/leftymuller)\
**Post date:** [29 November 2023 17:54 UTC](https://discourse.nodered.org/t/xml-manipulation-and-searching/83273/5 "2023-11-29T17:54:43Z")

</div>

Thanks for helping.

I Have spent the last 6 hours reading and playing around and I have made some progress.

Just one last thing

Im trying to search for "Rego" in the objects and return the value

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/7/079d809e58117fcbf263c5151c8972cd3afb431d.png)

Ive tried  
payload.**.name="Rego"  
payload.**.name.Rego  
payload.\*\*.job.sections.section.custom\_fields.custom\_field.Rego

These either return undefined or False

payload.\*\*.name returns a list with the target in it

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/8/28aff26dc1b160e7309332b926c4493972ec587c.png)

Any ideas?

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [29 November 2023 18:06 UTC](https://discourse.nodered.org/t/xml-manipulation-and-searching/83273/6 "2023-11-29T18:06:15Z")

</div>

> [@E1cid](#):
>
> Would provide an example but you have not given an example input and output in a form that is copyable.

I refer to my OG post.

with out data i can only offer a idea that may work, but i doubt it.

`payload.**.name[$ = "Rego"]`

As stated in OG reply I would need input data and output example.

---

<div class="post-metadata">

**Author:** ![leftymuller](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/leftymuller/32/102326_2.png) [@leftymuller](https://discourse.nodered.org/u/leftymuller)\
**Post date:** [30 November 2023 02:23 UTC](https://discourse.nodered.org/t/xml-manipulation-and-searching/83273/7 "2023-11-30T02:23:55Z")

</div>

Thanks.. Very helpful... and im nearly there!  
That returned  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/9/a984acf0f75bfccbd43c1a4ef39a9bb5440ce97b.png)

The Value im after is value  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/c/dc15a85a0609ea75e16450d8abacf17de4377b00.png)

I tried

```auto
payload.**.name[$ = "Rego"].value

```

That didnt work

I can see why you say the syntax of jsonata is hard!

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [30 November 2023 07:06 UTC](https://discourse.nodered.org/t/xml-manipulation-and-searching/83273/8 "2023-11-30T07:06:32Z")

</div>

This is my final guess without the asked for info, it is likely not correct as I have no idea of your objects correct format. Getting the correct expression from the information you have supplied is like fixing a car through a letter box.

`$$.payload.*[$.name[0] = "rego"].value[0]`

---

<div class="post-metadata">

**Author:** ![leftymuller](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/leftymuller/32/102326_2.png) [@leftymuller](https://discourse.nodered.org/u/leftymuller)\
**Post date:** [30 November 2023 07:29 UTC](https://discourse.nodered.org/t/xml-manipulation-and-searching/83273/9 "2023-11-30T07:29:02Z")

</div>

> [@E1cid](#):
>
> $$.payload.\*[$.name[0] = "rego"].value[0]

Tried that.. undefined

What info on the objects would you like me to post so you can see it all?

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [30 November 2023 07:32 UTC](https://discourse.nodered.org/t/xml-manipulation-and-searching/83273/10 "2023-11-30T07:32:14Z")

</div>

The complete object, copy payload and post here.

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/value 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)

p.s. I am out of house in 30 min wont be back at pc for 6-7 hours.

---

<div class="post-metadata">

**Author:** ![leftymuller](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/leftymuller/32/102326_2.png) [@leftymuller](https://discourse.nodered.org/u/leftymuller)\
**Post date:** [30 November 2023 07:40 UTC](https://discourse.nodered.org/t/xml-manipulation-and-searching/83273/11 "2023-11-30T07:40:00Z")

</div>

```auto
{"id":[{"_":"38688191","$":{"readonly":"readonly"}}],"job_type":[{"_":"job","$":{"readonly":"readonly"}}],"group_ids":["6855"],"status":["completed"],"third_party_id":[""],"enable_hazards":["false"],"is_incident":["false"],"taggings":[{"$":{"type":"array"}}],"hazards":[{"$":{"type":"array"}}],"time_windows":[{"$":{"type":"array"}}],"required_capacity":[""],"negative_time_windows":["false"],"customer_name":["NRMA Insurance"],"template_name":["ICRT Insurance Company Ring In Transfer"],"customer_id":["5830889"],"customer_third_party_id":["vwork16885941928796637"],"worker_id":["74271"],"worker_third_party_id":[""],"worker_name":["905 MZ"],"worker_duration":["2.3"],"published_at":[{"_":"2023-11-13T23:42:02+00:00","$":{"type":"datetime"}}],"published_by":[{"_":"Dispatch Maria Lang","$":{"readonly":"readonly"}}],"has_pod":[{"_":"false","$":{"readonly":"readonly"}}],"signed_at":[{"$":{"readonly":"readonly"}}],"signed_by":[{"$":{"readonly":"readonly"}}],"paused_at":[""],"planned_duration":["43200"],"planned_start_at":[{"_":"2023-11-13T04:47:29+00:00","$":{"type":"datetime"}}],"planned_end_at":[{"_":"2023-11-13T16:47:29+00:00","$":{"type":"datetime","readonly":"readonly"}}],"actual_start_at":[{"_":"2023-11-13T23:43:15+00:00","$":{"type":"datetime","readonly":"readonly"}}],"actual_duration":[{"_":"8289","$":{"readonly":"readonly"}}],"alarm_at":[{"$":{"type":"datetime"}}],"requested_at":[{"$":{"type":"datetime"}}],"code":[""],"notes":[{"$":{"type":"array"},"note":[{"id":[{"_":"3787402","$":{"readonly":"readonly"}}],"body":["Notes - "],"created_by_user_id":[{"_":"72074","$":{"readonly":"readonly"}}],"created_at":[{"_":"2023-11-08T04:52:22+00:00","$":{"readonly":"readonly","type":"datetime"}}],"updated_at":[{"_":"2023-11-08T04:52:22+00:00","$":{"readonly":"readonly","type":"datetime"}}]}]}],"adhoc_alert_email_recipient":[{"name":[""],"email":[""]}],"adhoc_alert_sms_recipient":[{"name":[""],"mobile":["61 "]}],"equipments":[{"$":{"type":"array"}}],"steps":[{"$":{"type":"array"},"step":[{"id":[{"_":"115523414","$":{"readonly":"readonly"}}],"name":["On Route"],"completed_at":[{"_":"2023-11-13T23:43:15+00:00","$":{"type":"datetime"}}],"created_at":[{"_":"2023-11-08T04:52:21+00:00","$":{"type":"datetime","readonly":"readonly"}}],"updated_at":[{"_":"2023-11-13T23:43:15+00:00","$":{"type":"datetime","readonly":"readonly"}}],"hazards_confirmation":[{"_":"false","$":{"type":"boolean"}}]},{"id":[{"_":"115523415","$":{"readonly":"readonly"}}],"name":["Vehicle on Board"],"completed_at":[{"_":"2023-11-14T02:01:23+00:00","$":{"type":"datetime"}}],"location":[{"id":[{"_":"127037575","$":{"type":"integer"}}],"created_at":[{"_":"2023-11-08T04:52:21+00:00","$":{"type":"datetime","readonly":"readonly"}}],"updated_at":[{"_":"2023-11-08T04:52:21+00:00","$":{"type":"datetime","readonly":"readonly"}}],"address1":[""],"address2":[""],"suburb":[""],"city":["Carlisle"],"post_code":["6101"],"country":["Australia"],"province":[""],"region":["AU"],"state":[""],"formatted_address":["BG Panel"],"lat":[{"_":"-31.988988","$":{"type":"decimal"}}],"lng":[{"_":"115.917907","$":{"type":"decimal"}}],"deleted_at":[{"$":{"type":"datetime"}}]}],"created_at":[{"_":"2023-11-08T04:52:21+00:00","$":{"type":"datetime","readonly":"readonly"}}],"updated_at":[{"_":"2023-11-14T02:01:23+00:00","$":{"type":"datetime","readonly":"readonly"}}],"hazards_confirmation":[{"_":"false","$":{"type":"boolean"}}]},{"id":[{"_":"115523416","$":{"readonly":"readonly"}}],"name":["Delivered to Destination"],"completed_at":[{"_":"2023-11-14T02:01:24+00:00","$":{"type":"datetime"}}],"location":[{"id":[{"_":"127037576","$":{"type":"integer"}}],"created_at":[{"_":"2023-11-08T04:52:21+00:00","$":{"type":"datetime","readonly":"readonly"}}],"updated_at":[{"_":"2023-11-08T04:52:21+00:00","$":{"type":"datetime","readonly":"readonly"}}],"address1":[""],"address2":[""],"suburb":[""],"city":["Bibra Lake"],"post_code":["6163"],"country":["Australia"],"province":[""],"region":["AU"],"state":[""],"formatted_address":["Pickles"],"lat":[{"_":"-32.095761","$":{"type":"decimal"}}],"lng":[{"_":"115.806365","$":{"type":"decimal"}}],"deleted_at":[{"$":{"type":"datetime"}}]}],"created_at":[{"_":"2023-11-08T04:52:21+00:00","$":{"type":"datetime","readonly":"readonly"}}],"updated_at":[{"_":"2023-11-14T02:01:25+00:00","$":{"type":"datetime","readonly":"readonly"}}],"hazards_confirmation":[{"_":"false","$":{"type":"boolean"}}]}]}],"sections":[{"$":{"type":"array"},"section":[{"title":["Dispatch Details"],"custom_fields":[{"$":{"type":"array"},"custom_field":[{"name":["Driver Image ID"],"value":[""],"type":["pick_list"],"pick_list_id":["143031"],"permission":["hidden"]},{"name":["Name of Auth Person"],"value":["Lee"],"type":["text"],"permission":["required"]},{"name":["Comp of Auth"],"value":["NRMA"],"type":["text"],"permission":["required"]},{"name":["Vehicle Good to Go"],"value":["Ready to go"],"type":["text"],"permission":["required"]}]}]},{"title":["Vehicle Details/Tow Authority"],"custom_fields":[{"$":{"type":"array"},"custom_field":[{"name":["Vehicle Type"],"values":[{"$":{"type":"array"},"value":["Car 4WD"]}],"type":["multi_pick_list"],"pick_list_id":["144389"],"permission":["required"]},{"name":["Rego"],"value":["1END171"],"type":["text"],"permission":["required"]},{"name":["Colour"],"value":["Blue"],"type":["pick_list"],"pick_list_id":["143033"],"permission":["required"]},{"name":["Make"],"value":["Jeep"],"type":["pick_list"],"pick_list_id":["145332"],"permission":["required"]},{"name":["Model"],"value":["Cherokee"],"type":["pick_list"],"pick_list_id":["143032"],"permission":["required"]},{"name":["Yard for Storage"],"values":[{"$":{"type":"array"},"value":["No Yard Required"]}],"type":["multi_pick_list"],"pick_list_id":["144879"],"permission":["required"]},{"name":["Additional Items Towed"],"value":[""],"type":["pick_list"],"pick_list_id":["146139"],"permission":["optional"]},{"name":["Signed Tow Authority"],"value":["https://api-nogzip.vworkapp.com/api/v5/attachments/file.jpg"],"attachment_id":["18662214"],"type":["image"],"permission":["optional"]},{"name":["Terms & Conditions"],"value":["https://tinyurl.com/3m94xyhh"],"type":["link"],"permission":["read_only"]},{"name":["Keys"],"values":[{"$":{"type":"array"},"value":["Yes"]}],"type":["multi_pick_list"],"pick_list_id":["142531"],"permission":["required"]},{"name":["Signature for Terms"],"value":[{"signature":[{"signed_by":[""],"signed_at":[{"$":{"type":"datetime"}}],"image":[""]}]}],"type":["signature"],"permission":["optional"]},{"name":["Location"],"lat":["0.0"],"lng":["0.0"],"formatted_address":[""],"type":["location"],"permission":["optional"]}]}]},{"title":["Vehicle Images "],"custom_fields":[{"$":{"type":"array"},"custom_field":[{"name":["Photo - Front"],"value":["https://api-nogzip.vworkapp.com/api/v5/attachments/file.jpg"],"attachment_id":["18659465"],"type":["image"],"permission":["required"]},{"name":["Photo - Side 1"],"value":["https://api-nogzip.vworkapp.com/api/v5/attachments/18659467.jpg"],"attachment_id":["18659467"],"type":["image"],"permission":["required"]},{"name":["Photo - Back"],"value":["https://api-nogzip.vworkapp.com/api/v5/attachments/18659472.jpg"],"attachment_id":["18659472"],"type":["image"],"permission":["required"]},{"name":["Photo - Side 2"],"value":["https://api-nogzip.vworkapp.com/api/v5/attachments/18659476.jpg"],"attachment_id":["18659476"],"type":["image"],"permission":["required"]},{"name":["Photo 4"],"value":[""],"type":["image"],"permission":["optional"]},{"name":["Photo 5"],"value":[""],"type":["image"],"permission":["optional"]},{"name":["Photo 6"],"value":[""],"type":["image"],"permission":["optional"]},{"name":["Photo 7"],"value":[""],"type":["image"],"permission":["optional"]},{"name":["Photo 8"],"value":[""],"type":["image"],"permission":["optional"]},{"name":["Photo 9"],"value":[""],"type":["image"],"permission":["optional"]}]}]},{"title":["Job Details Complete (Admin Section Only)"],"custom_fields":[{"$":{"type":"array"},"custom_field":[{"name":["Yard Zone"],"values":[{"$":{"type":"array"}}],"type":["multi_pick_list"],"pick_list_id":["146022"],"permission":["hidden"]},{"name":["VI Number"],"value":[""],"type":["text"],"permission":["optional"]},{"name":["Claim Number"],"value":["NRP1"],"type":["text"],"permission":["required"]},{"name":["Release Documents"],"value":[""],"type":["link"],"permission":["hidden"]},{"name":["Printing Status"],"value":["Printed"],"type":["pick_list"],"pick_list_id":["144880"],"permission":["hidden"]},{"name":["Job Details Complete"],"value":["1"],"type":["checkbox"],"permission":["hidden"]}]}]}]}],"invoice":[{"id":["5585103"],"number":["INV-3476"],"description":["Job Date: 14th Nov 2023\r\nJob Type: ICRT Insurance Company Ring In Transfer\r\nWorker Name 905 MZ\r\nContact Name: \r\nClaim Number: NRP1. \r\nRego: 1END171\r\nMake: Jeep \r\nModel: Cherokee\r\nPick Up Location: BG Panel\r\nDrop Off Location: Pickles, Australia\r\n\r\nOwner's Name: \r\nOwner's Ph No: 61 \r\nOwner's Address: \r\n"],"tax_rate":["10.0"],"pricebook_id":["1792"],"line_items":[{"$":{"type":"array"},"line_item":[{"id":["17974380"],"code":[""],"description":["905 MZ Distance(km) []"],"unit_cost":["0.0"],"requested_quantity":["0.0"],"actual_quantity":["15.8585036121208"]},{"id":["17980732"],"code":["IAG - Class 1 Transfer Tow"],"description":["INSURANCE GROUP - Class 1 (Up to 2030 Kgs), Transfer Tow / Second Tow (10 Kilometres Free)"],"unit_cost":["90.0"],"requested_quantity":["0.0"],"actual_quantity":["1.0"]},{"id":["17980733"],"code":["IAG - Class 1 Excess Kms"],"description":["INSURANCE AUSTRALIA GROUP - Class 1 (Up to 2030 Kgs), Excess Kilometres (10 Kilometres Free)"],"unit_cost":["3.0"],"requested_quantity":["22.0"],"actual_quantity":["12.0"]}]}]}],"created_at":[{"_":"2023-11-08T04:52:21+00:00","$":{"type":"datetime","readonly":"readonly"}}],"created_by":[{"_":"Dispatcher Ian","$":{"readonly":"readonly"}}],"updated_at":[{"_":"2023-11-14T06:49:24+00:00","$":{"type":"datetime","readonly":"readonly"}}]}

```

Does that help?

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [30 November 2023 07:46 UTC](https://discourse.nodered.org/t/xml-manipulation-and-searching/83273/12 "2023-11-30T07:46:12Z")

</div>

The path to the data item you want would also be needed. otherwise i would need to guess that to.

guess to correct property  
`$$.payload.**.custom_field[*][$.name[0] = "Rego"].value[0]`  
or

`$$.payload.**[*][$.name[0] = "Rego"].value[0]`

---

<div class="post-metadata">

**Author:** ![leftymuller](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/leftymuller/32/102326_2.png) [@leftymuller](https://discourse.nodered.org/u/leftymuller)\
**Post date:** [30 November 2023 08:00 UTC](https://discourse.nodered.org/t/xml-manipulation-and-searching/83273/13 "2023-11-30T08:00:28Z")

</div>

> [@E1cid](#):
>
> $$.payload.\*\*.custom\_field[\*][$.name[0] = "Rego"].value[0]

That worked!... Thank you so much!

Learning so much

Appreciate your help!

---

<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:** [14 December 2023 08:00 UTC](https://discourse.nodered.org/t/xml-manipulation-and-searching/83273/14 "2023-12-14T08:00:56Z")

</div>

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