CSV to XML Converter
Convert a CSV file into XML using a template with ##1##, ##2##… placeholders applied to every line of the CSV.
Option 2: Or upload your CSV file
Ctrl + Enter
Result
How the CSV to XML converter works
Unlike JSON, XML has no "natural" representation of a table, so this converter is template based: you describe the XML fragment to produce for one line of the CSV, using placeholders for the column values, and the fragment is repeated for every line. The fragments are wrapped in a root element and the result is re-indented.
Placeholder rules
##1##,##2##,##3##… are replaced by the first, second, third… column of the current line (positions start at 1).- A placeholder referring to a column that does not exist in a short line is replaced by an empty string.
- With "First line is a header", the first line is skipped. With "Use header names as placeholders too", you can also write
##first-name##to reference the column whose header isfirst-name(case-insensitive; the positional form keeps working). - A placeholder can be used several times and anywhere in the template: in text content, in attribute values, even in element names (as long as the result is a valid XML name).
- Values are escaped for XML by default (
&→&,<→<…). Uncheck the option only if your CSV cells already contain XML markup that must be inserted as-is. - Quoted values, embedded delimiters, doubled quotes (
"") and line breaks inside quotes are handled according to RFC 4180. Blank lines are ignored. - If the template produces XML that is not well-formed, the error is reported together with the number of the line that caused it.
Example
One line of CSV:
"1","Scott","Fargus","3159 W 11th Street","Cleveland","OH","USA","44109"
The template:
<person id="##1##">
<first-name>##2##</first-name>
<last-name>##3##</last-name>
<address>
<street>##4##</street>
<city>##5##</city>
<state>##6##</state>
<country>##7##</country>
<zip>##8##</zip>
</address>
</person>
The resulting XML (root element document):
<?xml version="1.0" encoding="UTF-8"?>
<document>
<person id="1">
<first-name>Scott</first-name>
<last-name>Fargus</last-name>
<address>
<street>3159 W 11th Street</street>
<city>Cleveland</city>
<state>OH</state>
<country>USA</country>
<zip>44109</zip>
</address>
</person>
</document>
Tip: to produce a flat structure without a template per column, use the CSV to JSON converter followed by the JSON to XML converter.