X4 Produktdokumentation

XML to CSV Converter

This adapter converts an XML file into a CSV file.

Properties

Operation

Defines the operation executed by the adapter.

Possible values:

  • Convert: Converts the XML file into a CSV file.

Parameters

headerInOutput

Required. Defines if there is a header in the CSV file to be created.

Possible values: true (default) / false

delimiter 

Required. Defines the delimiter in the CSV file to be created.

Possible values: Any delimiter, e.g. ;,  , (default) or \t (tab as delimiter)

lineEnd 

Required. Defines the character that marks the end of line in the CSV file to be created.

Possible values: Character for the end of line, e.g. \n (default Unix), \r\n (defaultMS Windows)

quotechar 

Defines the quotes for elements within the CSV file to be created.

Possible values:

  • Any quote character, e.g. " 

  • Default: Not set

escapechar 

Defines the character that escapes certain characters that would otherwise be interpreted as control characters.

Possible values:

  • Any character, e.g. "

  • Default: Not set

encoding 

Defines the character encoding for the operation.

Possible values:

  • Any character encoding, e.g. UTF-8 

  • Default: UTF-8 

Status values

1

The operation was executed successfully.

-1

The operation could not be executed.

Input

The adapter expects the following input structure:

Input Structure
XML
<?xml version="1.0" encoding="UTF-8"?>
<Csv>
    <Header>
        <Column name="columnName1" />
        <Column name="columnName2" />
        <Column ...
    </Header>
    <Records>
        <Record>
            <Column name="columnName1">value1</Column>
            <Column name="columnName2">value2</Column>
            <Column ...
        </Record>
        <Record>
            <Column name="columnName1">value1</Column>
            <Column name="columnName2">value2</Column>
            <Column ...
        </Record>
        <Record ...
    </Records>
</Csv>

If the parameter headerInOutput is set to true, a header is created in the output CSV file. The columns names are defined with the name attribute within the Header/Column element. As many columns are created as there are name attributes.

If the parameter headerInOutput is set to false, no header is created in the output CSV file. The number of columns created is the maximum number of Column elements within a Record element.

Each entry must be contained in a Record element. If a header is defined, the values are assigned to the column with the corresponding name.


Output

The adapter outputs a CSV document with the structure that is defined in the input document.

Example

Example Input XML to CSV Converter
XML
<?xml version="1.0" encoding="UTF-8"?>
<Csv>
    <Header>
        <Column name="Monday" />
        <Column name="Tuesday" />
        <Column name="Wednesday" />
    </Header>
    <Records>
        <Record>
            <Column name="Monday">First day</Column>
            <Column name="Tuesday">Second day</Column>
        </Record>
        <Record>
            <Column name="Monday">First day</Column>
            <Column name="Tuesday">Second day</Column>
            <Column name="Wednesday">Third day</Column>
        </Record>
    </Records>
</Csv>

The adapter parameters are set as follows:

  • headerInOutputtrue

  • delimiter,

  • encodingUTF-8

The above input leads to the following output:

Example Output XML to CSV Converter
XML
Monday,Tuesday,Wednesday
First day,Second day,
First day,Second day,Third day