CSV to XML component
The CSV to XML component provides a direct conversion from the CSV format to XML format. This component could, for example, be used when you receive CSV files from a FTP component.
Configuration
The CSV to XML component has the following configuration options:
Property | Default | Description |
---|---|---|
Delimiter | , | Specifies the delimiter character for the fields of a CSV line. |
Record seperator | new line | Specifies the seperator for records in the CSV. |
Use header | yes | If you want to use the first line of CSV to function as header values. If the first line of the CSV don't contain header values, set this to option to no . |
XML encoding | UTF-8 | Specifies the encoding for the resulting XML. |
Remarks
- The CSV can't contain duplicate headers. If your CSV contains duplicate headers, this can be solved by setting the
Use header
tono
. If you still want to use headers you can use another component like the Replace Component to change the headers of the CSV. - This component also supports Tab Seperated Values (TSV). Specify
\t
asDelimiter
if you need this feature.
Examples
There are two kinds of XML output. This depends on the Use header
option.
CSV with headers
Let's assume the CSV to XML component is configured as with the following settings:
Property | Value |
---|---|
Delimiter | , |
Record seperator | `` |
Use header | yes |
XML encoding | UTF-8 |
When given the CSV input...
first-name,last-name,age
Joe,Foo,21
John,Doe,30
...The CSV to XML component will yield the following output:
<?xml version="1.0" encoding="UTF-8"?>
<items>
<item>
<first-name>Joe</first-name>
<age>21</age>
<last-name>Foo</last-name>
</item>
<item>
<first-name>John</first-name>
<age>30</age>
<last-name>Doe</last-name>
</item>
</items>
CSV without headers
Let's assume the CSV to XML component is configured as with the following settings:
Property | Value |
---|---|
Delimiter | , |
Record seperator | `` |
Use header | no |
XML encoding | UTF-8 |
When given the CSV input... (without headers)
Joe,Foo,21
John,Doe,30
...The CSV to XML component will yield the following output:
<?xml version="1.0" encoding="UTF-8"?>
<items>
<item>
<string>Joe</string>
<string>Foo</string>
<string>21</string>
</item>
<item>
<string>John</string>
<string>Doe</string>
<string>30</string>
</item>
</items>