# How to loop comma seperated values in XML node into multiple XML nodes with each value in?

**URL:** <https://community.cdata.com/t/how-to-loop-comma-seperated-values-in-xml-node-into-multiple-xml-nodes-with-each-value-in/887>\
**Category:** CData Arc\
**Tags:** question\
**Created:** [August 23, 2024, 2:42pm UTC](https://community.cdata.com/t/how-to-loop-comma-seperated-values-in-xml-node-into-multiple-xml-nodes-with-each-value-in/887 "2024-08-23T14:42:57Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Origin-AnthonyR](https://sea3.discourse-cdn.com/cdata/user_avatar/community.cdata.com/origin-anthonyr/32/842_2.png) [@Origin-AnthonyR](https://community.cdata.com/u/Origin-AnthonyR)\
**Post date:** [August 23, 2024, 2:42pm UTC](https://community.cdata.com/t/how-to-loop-comma-seperated-values-in-xml-node-into-multiple-xml-nodes-with-each-value-in/887/1 "2024-08-23T14:42:57Z")

</div>

Hi,

We have an XML file that contains a node called /Items/delivery\_header/delivery\_line\_item/serial\_numbers&nbsp;and in that node we have a list of serial numbers separated by commas if there is more than one (e.g. 1 serial would just be XYZABC but 2 or more would be XYZABC,XYZDEF).

Is there a way on the destination XML to create a loop that can iterate through the comma separated values and create XML nodes like the following:

for a single serial number

SerialNumber

ManufacturerVersion = XYZABC

or for multiple serial number

SerialNumber

ManufacturerVersion = XYZABC

SerialNumber

ManufacturerVersion = XYZDEF

I have got as far as the below in the XML Map designer, I assume that I need to use a Loop with the nodes under it, but not sure what to use to split the values out, populate the ManufacturerVersion and then repeat with the next value:

 ![a0545381-3d2a-46b2-9af1-7571f7d2d039.png](https://us1.discourse-cdn.com/cdata/original/1X/3bc208809f585f672e893a9079f11b793bec3d58.png)

Any help would be appreciated.

Thanks,

Anthony.

---

<div class="post-metadata">

**Author:** ![Chaitanya\_Sandra](https://sea3.discourse-cdn.com/cdata/user_avatar/community.cdata.com/chaitanya_sandra/32/989_2.png) [@Chaitanya\_Sandra](https://community.cdata.com/u/Chaitanya_Sandra)\
**Post date:** [August 26, 2024, 6:00am UTC](https://community.cdata.com/t/how-to-loop-comma-seperated-values-in-xml-node-into-multiple-xml-nodes-with-each-value-in/887/2 "2024-08-26T06:00:03Z")

</div>

Hi Anthony,

Thank you for the detailed explanation here. I’m from CData Arc Support following up on your request here.

What you’re asking for here is a little tricky in XML Map, because the connector is designed to loop over anything that is addressed via XPath, but your **comma-separated** list of values is another array to loop over. The best way to handle this is to use ArcScript to load the list into a variable in memory using the map item:

> **[Map Item - CData Arc - Advanced | Version 24.3.9159](https://cdn.cdata.com/help/AZK/mft/XML-Map-Advanced.html#map-item)**
>
> The XML Map connector is designed to perform as much of the mapping as possible through the Mapping Editor. However there might be situations where scripting is required to handle custom use cases.

And then use the&nbsp;arc:enum&nbsp;keyword to enumerate over that as a list - anything between the arc:enum tags is rendered once per entry in the list, with [\_value] resolving to the entry in the list and [\_index] returning a one-based index, if you want that.

> **[CData Arc - arc:enum | Version 24.3.9159](https://cdn.cdata.com/help/AZK/mft/op_arcEnum.html)**

Visually, this looks like this (the connector is attached):

 ![2ae70724-251c-4ea0-8c1a-38fa68d56030.png](https://us1.discourse-cdn.com/cdata/original/2X/6/6feeab9710fd2e153b9cab47c422c178249e7ecd.png)

Steps followed to achieve this:

1. Created a virtual loop on the SerialNumber as shown in the above and map with the SerialNumber.

2. Created a Variable []ManufacturerVersion with the ManufacturerVersion from the source.

3. Created a Code Script with the following Code using&nbsp;arc:enum&nbsp;to enumerate over the attributes within a variable called [\_map.ManufacturerVersion], a delimited list. Remember that we are not closing the arc:enum here.

 ![dadd386a-0a85-484b-9fe4-ceb3c52c02c4.png](https://us1.discourse-cdn.com/cdata/original/2X/a/a6b85fc2748a63250307add6b23720d5e9cc549a.png)

4. Assign [\_value] to the desired field:&nbsp;The value of the attribute being iterated over. For a multivalued attribute, the expand and separator parameter settings determine whether the \_value is a reference to one attribute value or a reference to all attribute values.

5. At the end, you can close the enumeration.

Attached is the connector with an update for your reference, please let us know if this helps.

[XMLMap4.zip](https://community.cdata.com/uploads/short-url/jdQXvPnfB1Fiy0Vp7p56wyAhXZg.zip) (3.31 KB)

---

<div class="post-metadata">

**Author:** ![Chaitanya\_Sandra](https://sea3.discourse-cdn.com/cdata/user_avatar/community.cdata.com/chaitanya_sandra/32/989_2.png) [@Chaitanya\_Sandra](https://community.cdata.com/u/Chaitanya_Sandra)\
**Post date:** [August 26, 2024, 6:02am UTC](https://community.cdata.com/t/how-to-loop-comma-seperated-values-in-xml-node-into-multiple-xml-nodes-with-each-value-in/887/3 "2024-08-26T06:02:26Z")

</div>

Hi Anthony,

Here is the sample output response with the above ArcScript:

 ![62c8d3cc-30fa-437d-b784-969a6f26764f.png](https://us1.discourse-cdn.com/cdata/original/1X/bbc83686c19ba650671e687959fcd222ccf94a50.png)

---

<div class="post-metadata">

**Author:** ![Origin-AnthonyR](https://sea3.discourse-cdn.com/cdata/user_avatar/community.cdata.com/origin-anthonyr/32/842_2.png) [@Origin-AnthonyR](https://community.cdata.com/u/Origin-AnthonyR)\
**Post date:** [August 27, 2024, 1:57pm UTC](https://community.cdata.com/t/how-to-loop-comma-seperated-values-in-xml-node-into-multiple-xml-nodes-with-each-value-in/887/4 "2024-08-27T13:57:09Z")

</div>

Hi Chaitanya,

This was a great solution to the problem and helped me to understand the next steps.

Unfortunately I was using an older version of Arc and so had to modify my steps a little bit.

I found that the Loop was not needed as the source XML only contained a single node called “serial\_numbers” which contained the comma separated list and that this only appeared once in each of the parent ForEach anyway.

So I simply placed a Script, then the SerialNumber node, with ManufacturerVersion node as a child and then the final Scrip to stop the enum.

 ![57f8a3da-c618-4f8e-9e3c-d8ebe27aae57.png](https://us1.discourse-cdn.com/cdata/original/2X/e/ec892f827b0fde29712b22e610572317109dd7ea.png)

I have tested this with a single, multiple and empty value “serial\_numbers” node on the source and found that it correctly outputs either a single, multiple or none of the SerialNumber →&nbsp;ManufacturersVersion nested XML elements in destination.

Your help was greatly appreciate, and probably one of the best answers I have had on a community forum.

Thank you,

Anthony.

---

<div class="post-metadata">

**Author:** ![developer1.mapol](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@developer1.mapol](https://community.cdata.com/u/developer1.mapol)\
**Post date:** [March 19, 2025, 7:36pm UTC](https://community.cdata.com/t/how-to-loop-comma-seperated-values-in-xml-node-into-multiple-xml-nodes-with-each-value-in/887/5 "2025-03-19T19:36:30Z")

</div>

\<?xml version=“1.0” encoding=“UTF-8”?\>  
\<Items xmlns:json=“[http://arc.cdata.com/ns/jsonconnector](http://arc.cdata.com/ns/jsonconnector)” xmlns:xsi=“[http://www.w3.org/2001/XMLSchema-instance](http://www.w3.org/2001/XMLSchema-instance)”\>  
&nbsp; \<data json:array=“true”\>  
&nbsp; &nbsp; \<id json:type=“number”\>1723332\</id\>  
&nbsp; &nbsp; \<idn\>12\</idn\>  
&nbsp; \</data\>  
&nbsp; \<data json:array=“true”\>  
&nbsp; &nbsp; \<id json:type=“number”\>1722421\</id\>  
&nbsp; &nbsp; \<idn\>11\</idn\>  
&nbsp; \</data\>  
&nbsp; \<data json:array=“true”\>  
&nbsp; &nbsp; \<id json:type=“number”\>1718880\</id\>  
&nbsp; &nbsp; \<idn\>10\</idn\>  
&nbsp; \</data\>  
&nbsp; \<data json:array=“true”\>  
&nbsp; &nbsp; \<id json:type=“number”\>1715006\</id\>  
&nbsp; &nbsp; \<idn\>9\</idn\>  
&nbsp; \</data\>  
&nbsp; \<data json:array=“true”\>  
&nbsp; &nbsp; \<id json:type=“number”\>1714955\</id\>  
&nbsp; &nbsp; \<idn\>8\</idn\>  
&nbsp; \</data\>  
&nbsp; \<data json:array=“true”\>  
&nbsp; &nbsp; \<id json:type=“number”\>1713986\</id\>  
&nbsp; &nbsp; \<idn\>7\</idn\>  
&nbsp; \</data\>  
&nbsp; \<data json:array=“true”\>  
&nbsp; &nbsp; \<id json:type=“number”\>1712786\</id\>  
&nbsp; &nbsp; \<idn\>6\</idn\>  
&nbsp; \</data\>  
&nbsp; \<data json:array=“true”\>  
&nbsp; &nbsp; \<id json:type=“number”\>1712739\</id\>  
&nbsp; &nbsp; \<idn\>5\</idn\>  
&nbsp; \</data\>  
&nbsp; \<data json:array=“true”\>  
&nbsp; &nbsp; \<id json:type=“number”\>1712729\</id\>  
&nbsp; &nbsp; \<idn\>4\</idn\>  
&nbsp; \</data\>  
&nbsp; \<data json:array=“true”\>  
&nbsp; &nbsp; \<id json:type=“number”\>1709314\</id\>  
&nbsp; &nbsp; \<idn\>3\</idn\>  
&nbsp; \</data\>  
&nbsp; \<data json:array=“true”\>  
&nbsp; &nbsp; \<id json:type=“number”\>1703633\</id\>  
&nbsp; &nbsp; \<idn\>2\</idn\>  
&nbsp; \</data\>  
&nbsp; \<data json:array=“true”\>  
&nbsp; &nbsp; \<id json:type=“number”\>1701673\</id\>  
&nbsp; &nbsp; \<idn\>1\</idn\>  
&nbsp; \</data\>  
\</Items\>&nbsp; how arc script mutiple idn get

---

<div class="post-metadata">

**Author:** ![developer1.mapol](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@developer1.mapol](https://community.cdata.com/u/developer1.mapol)\
**Post date:** [March 19, 2025, 7:51pm UTC](https://community.cdata.com/t/how-to-loop-comma-seperated-values-in-xml-node-into-multiple-xml-nodes-with-each-value-in/887/6 "2025-03-19T19:51:08Z")

</div>

\<?xml version=“1.0” encoding=“UTF-8”?\>  
\<Items xmlns:json=“[http://arc.cdata.com/ns/jsonconnector](http://arc.cdata.com/ns/jsonconnector)” xmlns:xsi=“[http://www.w3.org/2001/XMLSchema-instance](http://www.w3.org/2001/XMLSchema-instance)”\>  
&nbsp; \<data json:array=“true”\>  
&nbsp; &nbsp; \<id json:type=“number”\>1723332\</id\>  
&nbsp; &nbsp; \<idn\>12\</idn\>  
&nbsp; \</data\>  
&nbsp; \<data json:array=“true”\>  
&nbsp; &nbsp; \<id json:type=“number”\>1722421\</id\>  
&nbsp; &nbsp; \<idn\>11\</idn\>  
&nbsp; \</data\>  
&nbsp; \<data json:array=“true”\>  
&nbsp; &nbsp; \<id json:type=“number”\>1718880\</id\>  
&nbsp; &nbsp; \<idn\>10\</idn\>  
&nbsp; \</data\>  
&nbsp; \<data json:array=“true”\>  
&nbsp; &nbsp; \<id json:type=“number”\>1715006\</id\>  
&nbsp; &nbsp; \<idn\>9\</idn\>  
&nbsp; \</data\>  
&nbsp; \<data json:array=“true”\>  
&nbsp; &nbsp; \<id json:type=“number”\>1714955\</id\>  
&nbsp; &nbsp; \<idn\>8\</idn\>  
&nbsp; \</data\>  
&nbsp; \<data json:array=“true”\>  
&nbsp; &nbsp; \<id json:type=“number”\>1713986\</id\>  
&nbsp; &nbsp; \<idn\>7\</idn\>  
&nbsp; \</data\>  
&nbsp; \<data json:array=“true”\>  
&nbsp; &nbsp; \<id json:type=“number”\>1712786\</id\>  
&nbsp; &nbsp; \<idn\>6\</idn\>  
&nbsp; \</data\>  
&nbsp; \<data json:array=“true”\>  
&nbsp; &nbsp; \<id json:type=“number”\>1712739\</id\>  
&nbsp; &nbsp; \<idn\>5\</idn\>  
&nbsp; \</data\>  
&nbsp; \<data json:array=“true”\>  
&nbsp; &nbsp; \<id json:type=“number”\>1712729\</id\>  
&nbsp; &nbsp; \<idn\>4\</idn\>  
&nbsp; \</data\>  
&nbsp; \<data json:array=“true”\>  
&nbsp; &nbsp; \<id json:type=“number”\>1709314\</id\>  
&nbsp; &nbsp; \<idn\>3\</idn\>  
&nbsp; \</data\>  
&nbsp; \<data json:array=“true”\>  
&nbsp; &nbsp; \<id json:type=“number”\>1703633\</id\>  
&nbsp; &nbsp; \<idn\>2\</idn\>  
&nbsp; \</data\>  
&nbsp; \<data json:array=“true”\>  
&nbsp; &nbsp; \<id json:type=“number”\>1701673\</id\>  
&nbsp; &nbsp; \<idn\>1\</idn\>  
&nbsp; \</data\>  
\</Items\>&nbsp; &nbsp;how to use all idn below arc

\<!-- Read XML --\>  
\<arc:set attr=“input.uri” value=“[FilePath]”/\>  
\<arc:call op=“xmlOpen” input=“input”\>  
&nbsp; \<arc:set attr=“xml.handle” value=“[handle]” /\>  
\</arc:call\>  
\<arc:set attr=“xml.map:data” value=“/items/data”/\>  
\<arc:enum range=“1..[output.header:idn]”\>  
arc:try  
&nbsp; \<arc:call op=“xmlDOMGet” in=“xml” out=“out1”\>  
&nbsp; &nbsp; \<arc:set attr=“data.idn” &nbsp; &nbsp; value=“[out1.idn]”/\>  
&nbsp; \</arc:call\>  
&nbsp;&nbsp;  
\<!-- Log Information --\>  
\<arc:set attr=“\_log.info”\>  
idn = [data.idn]  
\</arc:set\>

\<!-- fetch Shipment Details from DigiHaul --\>  
\<arc:set attr=“http.URL” value=“[https://api.domain.com/sales/\[data.idn]](https://api.domain.com/sales/%5C%5Bdata.idn%5D)” /\> &nbsp;  
\<arc:set attr=“http.header:name#” value=“TOKEN” /\>  
\<arc:set attr=“http.header:value#” value=“a6566566666666666fgdfgdfgdfgdfgdfg”/\>

\<arc:set attr=“http.verbosity” value=“5”/\>&nbsp;  
\<arc:set attr=“http.logfile” value=“D:\cData\logs\my.log”/\>

\<arc:set attr=“\_log.info”\>  
Auth = [http.header:\*]  
URL = [http.URL] &nbsp;  
\</arc:set\>

\<arc:call op=“httpGet” in=“http”\>  
&nbsp; \<arc:set attr=“output.data” value=“[http:content]” /\>  
\</arc:call\>

\<arc:set attr=“\_log.info”\>  
Response = [output.data]  
\</arc:set\>

\<arc:set attr=“output.filename” value=“dh-fetch-order-[data.idn].json” /\>  
\<arc:push item=“output” /\>

arc:finally  
&nbsp; &nbsp; \<arc:call op=“xmlClose” input=“xml”/\>  
&nbsp; \</arc:finally\>  
\</arc:try\>  
&nbsp; \</arc:enum\>

---

<div class="post-metadata">

**Author:** ![developer1.mapol](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@developer1.mapol](https://community.cdata.com/u/developer1.mapol)\
**Post date:** [March 19, 2025, 7:54pm UTC](https://community.cdata.com/t/how-to-loop-comma-seperated-values-in-xml-node-into-multiple-xml-nodes-with-each-value-in/887/7 "2025-03-19T19:54:22Z")

</div>

example please
