Skip to main content

Hi,

 

We have an XML file that contains a node called /Items/delivery_header/delivery_line_item/serial_numbers 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:

 

 

Any help would be appreciated.

 

Thanks,

 

Anthony.

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:

https://cdn.cdata.com/help/AZK/mft/XML-Map-Advanced.html#map-item

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

https://cdn.cdata.com/help/AZK/mft/op_arcEnum.html

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


 

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 r]ManufacturerVersion with the ManufacturerVersion from the source.

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


4. Assign 4_value] to the desired field: 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.


Hi Anthony,

Here is the sample output response with the above ArcScript:
 

 


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.

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 → 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.


Reply