I have a comma delimited file that I am going to use the Flat File Parser to convert to XML. The problem is one of the fields is a free flow entry and, at times, the users enter a comma in the field which causes the system to go bonkers because we end up with an extra field.
Can I use the For Each process step to go through the text file line by line to delete the errant commas? If so is there an example of how to set it up, i.e., Collection Property Name, Item Property Name and how to refer to it in the code section?
Tags:
The For Each process step will only iterate through a collection that exists in memory. You would need to first read the lines of the text file into something like a List<string> object using a code step, and put the list object into the context.Properties collection. Then you can pass that list to the ForEach process step and operate on each line.
To run the ForEach step, you would set the CollectionPropertyName property to the name of the list that you stored in the context.Properties dictionary. The ItemPropertyName property is set with the name that you want to use to reference the current item from the list inside of the loop.
For example:
Since the message is already on the bus looking like:
1,2,2014-01-20 00:00:00.000,3953,1061633, XXXXXXXXXXXX8928,0
2,2,2014-01-20 00:00:00.000,3944,1061585, TXSH 1,0
3,2,2014-01-20 00:00:00.000,6490,1061583, XXXXXXXXXXXX4853,0
4,2,2014-01-20 00:00:00.000,4126,1061560, Pickup By,0
5,2,2014-01-20 00:00:00.000,4126,1061560, Antoine Alexander,0
6,2,2014-01-20 00:00:00.000,4126,1061560, 214-622-7792,0
7,2,2014-01-20 00:00:00.000,4126,1061560, Guarantee Level,0
8,2,2014-01-20 00:00:00.000,4126,1061560, 15 minutes,0
9,2,2014-01-20 00:00:00.000,4126,1061560, Target Pickup Time,0
10,2,2014-01-20 00:00:00.000,4126,1061560, 11:44 AM,0
Shouldn't I be able to reference it similar to:
context.Properties["FileLines"] = context.Data.Text;
to make my Properties?
Not exactly. You will need to use a code step to split the text using newlines. For example:
context.Properties["FileLines"] = context.Data.Text.Split(new[] { '\n' }, StringSplitOptions.RemoveEmptyEntries);
or
context.Properties["FileLines"] = context.Data.Text.Split(new[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
depending on whether your lines are terminated by LF characters (\n) or CRLF (\r\n). The latter may be the case.
Neuron ESB Product Support Forums and Communities
© 2024 Created by Neuron Admin. Powered by