Converting CSV files to XML
This tutorial will help you to convert CSV files to XML format using the CSV to XML task in Zynk.
The CSV to XML Task
Most of the tasks within Zynk are set up to use standard XML as the input and output. In some cases, outside systems may provide data in other formats (such as CSV). This tutorial demonstrates how to use this task by taking an example CSV file and converting it to XML.
CSV to XML
In this example, we will use the following example CSV file:
UniqueId,Sku,Barcode,Name,Description,SalePrice,UnitWeight,QtyInStock,QtyOnOrder,ReorderQty,ReorderLvl,TaxCode,GroupCode,GroupName,Department,UnitOfSale,NominalCode,Publish,ProductLevel,SpecialOffer,QtyAllocated,ImageName,LastCostPrice,LastCostPriceDiscounted,QtyLastOrder,AverageCostPrice,SupplierDepartment,PurchaseNominalCode,UseDescriptionOnDocs,ItemType,IsActive
"PRODUCT","PRODUCT","5019301023118","Test Product","Test Product for Sage 50","396","0","0","0","0","0","1","14","Other","6","EA","4000","false","0","false","0","(none)","316.8","316.8","7","316.8","6","5006","false","Service","true"
On this task you will see the following settings:
- Column Name Prefix - The prefix that will be used with the Column Index for auto generated Column names (only applicable if Headers are not specified). Column names are used when generating the Context Variables.
- Delimiter - The character to use to delimit the data in the CSV file. Usually this will be either a quotation mark or just left blank.
- Encoding Type - The encoding to use when parsing the Input.
- Include Headers - Set this to true to interpret the first row of the Input as column names. Column names are used when generating the Context Variables.
- Input - The CSV file to convert to XML.
- Separator - The separator to use in the output CSV file. This will usually be a comma.
- Export as Elements - Set to true to output the value of each column as an XML element node, or false to output them as XML attributes. Defaults to true.
- Output File - The name of the XML file to create containing the XML representation of the Excel worksheet
- Root - The name to use for the root XML element in the generated Output File. This is set to "Products" for this example.
- Row - The XML element name to use for each row in the generated Output File. This is set to "Product" for this example.
This creates the following output:
<?xml version="1.0" encoding="utf-8"?>
<Products>
<Product>
<UniqueId>PRODUCT</UniqueId>
<Sku>PRODUCT</Sku>
<Barcode>5019301023118</Barcode>
<Name>Test Product</Name>
<Description>Test Product for Sage 50</Description>
<SalePrice>396</SalePrice>
<UnitWeight>0</UnitWeight>
<QtyInStock>0</QtyInStock>
<QtyOnOrder>0</QtyOnOrder>
<ReorderQty>0</ReorderQty>
<ReorderLvl>0</ReorderLvl>
<TaxCode>1</TaxCode>
<GroupCode>14</GroupCode>
<GroupName>Other</GroupName>
<Department>6</Department>
<UnitOfSale>EA</UnitOfSale>
<NominalCode>4000</NominalCode>
<Publish>false</Publish>
<ProductLevel>0</ProductLevel>
<SpecialOffer>false</SpecialOffer>
<QtyAllocated>0</QtyAllocated>
<ImageName>(none)</ImageName>
<LastCostPrice>316.8</LastCostPrice>
<LastCostPriceDiscounted>316.8</LastCostPriceDiscounted>
<QtyLastOrder>7</QtyLastOrder>
<AverageCostPrice>316.8</AverageCostPrice>
<SupplierDepartment>6</SupplierDepartment>
<PurchaseNominalCode>5006</PurchaseNominalCode>
<UseDescriptionOnDocs>false</UseDescriptionOnDocs>
<ItemType>Service</ItemType>
<IsActive>true</IsActive>
</Product>
</Products>