This script converts Tab Separated Values (TSV), Comma Separated Values (CSV), or similar String Separated Values (SSV) into Extensible Markup Language (XML).
It expects a single header row, the column headers in which are used to create element (tag) or attribute names in the output. Illegal characters such as whitespace (in element and attribute names), &, <, and > are escaped. Additionally you must specify the element names for the entire file and each row as part of your input. You must ensure that there are no examples of separators inside quoted strings within the data.
The optional attributes list is a comma separated list of column numbers which are to be made attributes of each row tag.
The optional exclusions list is a comma separated list of column numbers which are to be omitted from the output.
By default a comment, "Created by: <This URL>, <Date>", will be added to the output. This can be edited, or omitted altogether by blanking it.
Further, as long as source data and comments are not mixed on the same line, the convertor can copy existing markup comments, denoted by <!-- -->, &/or convert a choice of other comments from standard filetypes, or those specified by a Regular Expression (RE) The following table describes this functionality:
|Online Version||Download Version||Description|
|No comments||Treat all source as data.|
|Use this RE||-C:<RE>||Convert comments captured by the specified RE and copy existing markup comments. If RE is blank, no conversion occurs but existing markup comments are copied. If RE is a single character, an RE is constructed around it to convert single line comments denoted by the specified character being the leading non-blank character.|
|Assembler/INI/REG||-C:;||Convert single line comments denoted by a leading ; and copy existing markup comments.|
|Basic/VB||-C:'||Convert single line comments denoted by a leading ' and copy existing markup comments.|
|C/Java/JS||-C:c||Convert single and multi line C/Java/JS comments denoted by // and /* */ and copy existing markup comments.|
|Properties||-C:#||Convert single line comments denoted by a leading # and copy existing markup comments.|
To use this online version, paste your SSV data into the input, set the parameters, click Submit, and copy the resulting XML output. To download the console script to your PC, <Right-Click> SSV2XML.js and choose Save As.
|13/06/2010||v1.1 - Safer Array for() loops if the Array.prototype is altered.|