CSV to XML
You need to convert one or more CSV files to a XML format.
Json
Example
json
{
"name": "file-conversion-csv-to-xml",
"taskReferenceName": "csv_to_xml",
"description": "The business description of the task",
"type": "SUB_WORKFLOW",
"optional": false,
"inputParameters": {
"mode": "FILE",
"file": "${previous_TaskReferenceName.output.file}",
"columnSeparator": ";",
"textDelimiter": "\"",
"escapeCharacter": "\""
}
}1
2
3
4
5
6
7
8
9
10
11
12
13
14
2
3
4
5
6
7
8
9
10
11
12
13
14
Definition
| Property | Type | Required | Description |
|---|---|---|---|
| The name (or type) of the task | |||
| The unique name of the task in your job. It is used to reference this task in the workflow. | |||
| The functional description of this task in your job. | |||
The type of the task. It must be SUB_WORKFLOW. | |||
| : | true: the job continues if there is an error on this task. false: the job fails. | ||
| Input parameters of the task. See below |
Inputs
| Property | Type | Required | Description |
|---|---|---|---|
| mode | : | ||
| file | It can reference the output of a previous task, example: ${previous_taskReferenceName.output.file} , or a static file, example: file://assets/file.csv, or a user input, example: ${workflow.input.input_key}. | ||
| files | It can reference the output of a previous task, example: ${previous_taskReferenceName.output.files} , or a user input, example: ${workflow.input.input_key}. | ||
| columnSeparator | The column separator. Usually ; or , or | | ||
| textDelimiter | How text are encapsulated. Usually " or ' | ||
| escapeCharacter | If the text contains the text qualifier character, then it must be escaped. The escape character is usually the same than the text textDelimiter. For example: "Produit 1";"Télé 51"" ou plus" | ||
| allowEmpty | : | true: empty values are exported, false: empty values are not exported. Default: false. | |
| fileName | The name of the generated XML file. When it is omitted, mode = FILE names the output after the input file (products.csv gives products.xml) and mode = FILES produces file.xml. | ||
| : | Default: falseWhen set to true, the report generation is skipped and thus the report is not available in the output parameters. | ||
| : | Default: info It defines the log level to be recorded in the report. error < warning < info < debug |
Outputs
| Property | Type | Description |
|---|---|---|
| file | An XML file as described below. | |
| allFilesTransformed | YES | NO. YES: all files have been transformed successfully. NO: at least one file has not been transformed. Only present when mode = FILES. |
Output file
Example
xml
<Csv-To-Xml>
<File>
<File-Name>products.csv</File-Name>
<Rows>
<R i="1">
<C j="1">EAN</C>
<C j="2">1234567890123</C>
<C j="3">1234567890124</C>
</R>
</Rows>
</File>
</Csv-To-Xml>1
2
3
4
5
6
7
8
9
10
11
12
2
3
4
5
6
7
8
9
10
11
12
Definition
| XPath | Description | Occurs |
|---|---|---|
| Csv-To-Xml | Root of the document. | 1 |
| ./File | For each input file. | 1..* |
| ./File/File-Name | Original file name. | 1 |
| ./File/Rows | Rows. | 1 |
| ./File/Rows/R | R = Row, one by row. | 0..* |
| ./File/Rows/R/@i | i = line index, start index is 1. | 1 |
| ./File/Rows/R/C | C = Column. One by cell, nested inside its R. | 0..* |
| ./File/Rows/R/C/@j | j = column index, start index is 1. | 1 |
Characters that XML does not allow - control characters, surrogates, non-characters - are removed from every value. What remains is written as text, never wrapped in a CDATA section. Only three characters are encoded, as &, < and >; everything else is written as-is, accented and other non-ASCII characters included. A cell with no value is omitted entirely unless allowEmpty is true.
The document is generated without indentation, to keep it as small as possible.
What happens when a file cannot be converted
In mode = FILES the files are processed in the order of the files input, and that order is preserved in the output.
A file whose conversion fails does not stop the task: its <File> element is still written, with its File-Name but without its rows, allFilesTransformed becomes NO, and the task completes. There is therefore one <File> per input file, converted or not - count rows, not <File> elements, to tell what actually came through.
A file that cannot be downloaded is different: it ends the task in error.
Limits and additional notes
- The limitation of the input file size is 250 Mb.
- The input file must be encoded in UTF-8
FAQ
Can I convert a .txt file?
Yes. The extension is not checked - the input is parsed as delimited text according to columnSeparator, textDelimiter and escapeCharacter, whatever the file is called.