Transforming a CSV Document Containing Reserved Words to XML Format
Search form
This topic describes how to transform a CSV document containing reserved words to XML format. In the following example, a CSV input document contains an “OR” value in the fourth header column (D).
________________________________________________________
Click here to download a PDF version of this How-to.
________________________________________________________
Values such as “OR” are interpreted as conditional operators and are not supported in the context parser of the transformation engine. Instead, they are interpreted as conditional operators in the following XPath:
[space]OR[space]
There are three workarounds available, which are described in the following topics:
- Escaping the operators clause in the header.
- Removing the header before calling transformer.
- Using a variable.
Escaping the Operators Clause in the Header
The CSVTransform_Test_with_escape.zip archive file that is included with this how-to contains a sample transform where the input data has an updated header, as shown in the following image.
The header in the input document was updated before configuring (calling) the transform by replacing the operators clause (OR, AND, |, &) with an escape character. For example:
[space]OR[space]
is modified as:
[space]\OR[space]
Removing the Header Before Configuring the Transform
Edit the CSV input document by removing the first record before configuring the transform. This allows you to configure the transform without the header in the input document. Ensure to deselect the Contains Header option in the input document properties.
Using a Variable
The CSV_Fix_variable.zip archive file that is included with this how-to contains a sample transform where the mappings use a variable to bypass the first record in the input document, as shown in the following image.
Using this approach, there is no need to modify the input document before configuring the transform.
In the input document properties for this transform, notice that the Contains Header option is deselected, as shown in the following image.
This indicates that the transform is being configured without including the header in the input document.
In addition, the header is skipped in this transform by using a variable to bypass the first record and only show the group of output elements if the count is greater than one (1), as shown in the following image.