Adapter requests and responses for the CSV adapter
This section describes the requests and responses of the CSV adapter for the following actions:
- Read
- Write
- Delete
CSV adapter request and responses for the Read action
The Read action reads the data in the CSV file.
The following table describes the adapter request elements for the CSV adapter with a Read action.
Element | Description | Required |
---|---|---|
<file-name> | Specifies the name and location of the file which you want the adapter to read | Yes |
<delimiter> | Specifies a character that is used to indicate the end of one field and the beginning of the next Default value: , | No |
<text-qualifier> | Specifies a character that differentiates field data from a delimiter Each field's data is between the text qualifier. For example, the field data contains a comma and a comma is used as a record delimiter, then text qualifier must be used to distinguish between the comma’s in the data and the comma’s used to delimit fields. Default value: (") | No |
<read-headers> | Specifies whether to read the first row in the data as column headers Valid values: true, false (default) | No |
<charset> | Specifies the supporting CharSet Also called character set, it includes identifiers describing a series of universal characters. | No |
<start-index> | Specifies the row from where the adapter starts reading the rows in the CSV file Default value: 0 0 indicates that the adapter starts reading the CSV file data from the first row. | No |
<maximum-rows> | Specifies the number of rows to be read from the CSV file starting from the start index For example: if the Default value: 0; reads all rows in a file. | No |
The following figure describes an XML request sample for the CSV adapter with a Read action.
XML request sample for the CSV adapter with a Read action
<csv-adapter-request>
<start-index />
<operation-name>read</operation-name>
<file-name>C:\test.csv</file-name>
<delimiter />
<text-qualifier />
<read-headers />
<maximum-rows />
<charset />
</csv-adapter-request>
The following figure describes a sample response for the CSV adapter with a Read action
XML response sample for the CSV adapter with a Read action
<csv-adapter-response>
<metadata>
<status>success</status>
</metadata>
<read-response>
<rows row-count="2">
<row index="1">
<column index="1">Name'Education'Designation</column>
</row>
<row index="2">
<column index="1">Martin'B.tech'"Lead "</column>
</row>
</rows>
</read-response>
</csv-adapter-response>
CSV adapter request and responses for the Write action
The Write action writes the data to the CSV file.If a file already exists, the Write action overwrites the rows in the file, without any indication.
The following table describes the adapter request elements for the CSV adapter with a Write action.
Element | Description | Required |
---|---|---|
<file-name> | Specifies the name and location of the file which you want the adapter to read | Yes |
<delimiter> | Specifies a character that is used to indicate the end of one field and the beginning of the next Default value: (,) | No |
<text-qualifier> | Specifies a character that differentiates field data from a delimiter Each field's data is between the text qualifier. For example, the field data contains a comma and a comma is used as a record delimiter, then text qualifier must be used to distinguish between the comma’s in the data and the comma’s used to delimit fields. Default value: (") | No |
<preserve-spaces> | Specifies whether to preserve spaces between the values in a CSV file Valid value: true, false | No |
<charset> | Specifies the supporting CharSet Also called character set, it includes identifiers describing a series of universal characters. | No |
<rows> | Specifies a row to be added to the CSV file Contains the columns element. | Yes |
<column> | Specifies the column to be created within a row in the CSV file | Yes |
The following figure describes an XML request sample for the CSV adapter with a Write action.
XML request sample for the CSV adapter with a Write action
<csv-adapter-request>
<operation-name>write</operation-name>
<file-name>C:\test.csv</file-name>
<delimiter>'</delimiter>
<text-qualifier>"</text-qualifier>
<preserve-spaces>true</preserve-spaces>
<charset />
<rows>
<row>
<column>Name</column>
<column>Education</column>
<column>Designation</column>
</row>
<row>
<column>Martin</column>
<column>B.tech</column>
<column>Lead </column>
</row>
</rows>
</csv-adapter-request>
The following figure describes a sample response for the CSV adapter with a Write action
XML response sample for the CSV adapter with a Write action
<csv-adapter-response>
<metadata>
<status>success</status>
</metadata>
<write-response>
<number-of-rows-written>2</number-of-rows-written>
</write-response>
</csv-adapter-response>
CSV adapter request and responses for the Delete action
The Delete action deletes rows in the CSV file.
The following table describes the adapter request elements for the CSV adapter with a Delete action.
Element | Description | Required |
---|---|---|
<file-name> | Specifies the name and location of the file in which you want to delete specified rows | Yes |
<delimiter> | Specifies a character that is used to indicate the end of one field and the beginning of the next Default value: , | No |
<text-qualifier> | Specifies a character that differentiates field data from a delimiter Each field's data is between the text qualifier. For example, the field data contains a comma and a comma is used as a record delimiter, then text qualifier must be used to distinguish between the comma’s in the data and the comma’s used to delimit fields. Default value: (") | No |
<read-headers> | Specifies whether to read the first row in the data as column headers Valid values: true, false (default) | No |
<charset> | Specifies the supporting CharSet Also called character set, it includes identifiers describing a series of universal characters. | No |
<start-index> | Specifies the row from where you can start deleting the rows in the CSV file Default Value: 0 If the | No |
<maximum rows> | Specifies the number of rows to be deleted from the CSV file starting from start index Default Value: 0 (No rows are deleted) For example: if the | No |
The following figure describes an XML request sample for the CSV adapter with a Delete action.
XML request sample for the CSV adapter with a Delete action
<csv-adapter-request>
<start-index>1</start-index>
<operation-name>delete</operation-name>
<file-name>C:\test.csv</file-name>
<delimiter />
<text-qualifier />
<read-headers />
<maximum-rows>2</maximum-rows>
<charset />
</csv-adapter-request>
The following figure describes a sample response for the CSV adapter with a Delete action
XML response sample for the CSV adapter with a Delete action
<csv-adapter-response>
<metadata>
<status>success</status>
</metadata>
<delete-response>
<rows row-count="2">
<row index="1">
<column index="1">Name'Education'Designation</column>
</row>
<row index="2">
<column index="1">Martin'B.tech'"Lead "</column>
</row>
</rows>
</delete-response>
</csv-adapter-response>
Comments
Sure would like to see responses for basic error conditions, i.e. file not found (read/delete), file already exists (write), start index is greater than the number of rows in the file (read/delete).
Your description of <preserve-spaces> makes no sense. I think you mean either "Preserve spaces between values" or "Preserve spaces between columns". There are NEVER any spaces between rows.
For the <delimiter> description, use (,) instead of just the plain comma (like you did for <text-qualifier>).
Done, made the change.
Made the change.
Thanks!
Is there a limitation in file read request in terms of number of characters in a cell of a CSV file? Otherwise is it possible to read a cell data with multiple lines of data in it.
Hi Saravanan,
Not that I am aware of any such limitations. Let me still confirm with the team and get back to you.
Thanks!
Log in or register to comment.