How to parse a CSV file in which the Cell contains the Carriage Return (CR) character.

How to parse a CSV file in which the Cell contains the Carriage Return (CR) character.

book

Article ID: KB0085058

calendar_today

Updated On:

Products Versions
TIBCO ActiveMatrix BusinessWorks -
Not Applicable -

Description

Resolution:
Description:
========
How to parse a CSV file in which the Cell contains the Carriage Return (CR) character.

Environment:
========
ALL

Resolution:
========
When editing a CSV file in Excel, some cells may contain several lines. Those lines are also marked by CR. Since some CSV files may also use CR as the global line separator, BW will not be able to parse such a file using "Parse Data Activity" correctly. In this case, use custom Java code to parse the CSV file and then covert the data back to an XML format. Refer to the attached sample project (Filename: CSVParser.zip).


1). Custom Java code for parsing CSV file.

    

- Create a Java POJO class which will act as the data wrapper for a single line of CSV file. For example, if you have three columns in a CSV file, you would need to define three instance variables in the POJO as well as the Getter/Setter method.

  
- The CR character in the cell is surrounded by double quotes ("") and will be recognized as the true line separator.
  
- The output of the Custom Java code activity is Object[], which is actually the array of the POJO class.
  
2). Convert the Object[] reference to XML format. Java to XML activity can be used to convert the Java object to XML data. The POJO class created in step (1) is also used here. Note that the Java POJO class needs to be placed into a JAR file so that it can be included into the classpath of bwengine/designer.

Issue/Introduction

How to parse a CSV file in which the Cell contains the Carriage Return (CR) character.

Attachments

How to parse a CSV file in which the Cell contains the Carriage Return (CR) character. get_app