Search code examples
csvbiztalkflat-file

Get Flat File Schema as CSV output when input data has newlines


Consider my input data as below:

<xmlnode>line1    
line2    
line3    
</xmlnode>

Right now, I have a map which maps input data to a flatfile schema. I am saving the flatfile as CSV.

Issue is :if input data is having newlines, then the csv format is getting corrupted. The content of 'xmlnode' should go to one single csv column.

Is there is any setting I need to handle this at flat file schema?


Solution

  • Create a functoid with code like the following:

    return input.Replace("\r", "").Replace("\n", " ");
    

    The idea is to replace any \r\n with a single space (and handle cases where there's a newline with no carriage return). Should fix your problem.

    If this is a problem that will occur routinely on multiple/all nodes from your input, then you might consider running that as a regular expression on the entire message as a string after mapping (rather than having every node pass through your scripting functoid).

    As Dan suggessted in Comments, double quotes is also required to save data with \n (new line) in one cell of a csv.