Convert CSV to XML
This tool turns a CSV file with a header row into an XML document — one record element per row, with a child element for each column. It is useful for producing XML feeds, config files, or import payloads from a spreadsheet export without writing a script.
How it works
The CSV is parsed with an RFC 4180 scanner, so quoted fields containing commas,
line breaks, or doubled quotes ("") are handled correctly. The first row supplies
the column names, and each later row becomes one record element.
You choose the root element name (default rows) and the row element name
(default row). Each header is sanitised into a valid XML element name: invalid
characters and spaces become underscores, and names beginning with a digit get a
leading underscore. Cell values are entity-escaped — &→&, <→<,
>→> — so the output is always well-formed. The document is emitted with an
XML declaration, either pretty-printed with indentation or minified to a single line.
Example
The CSV name,city with a row Ada,London produces:
<?xml version="1.0" encoding="UTF-8"?>
<rows>
<row>
<name>Ada</name>
<city>London</city>
</row>
</rows>
Common use cases
Data interchange with legacy systems. Many enterprise ERP, CRM, and accounting platforms accept XML imports but not CSV directly. Exporting from a spreadsheet or reporting tool to CSV and then converting here avoids writing a one-off script every time the schema changes.
Producing XML feeds. Simple RSS or Atom feeds, product catalog feeds, and syndication XML all have a flat-record structure (one element per item) that maps naturally from CSV. The configurable root and row tag names let you match the target schema without post-processing.
Configuration from a spreadsheet. When a team manages configuration in a shared spreadsheet and the target system wants XML, this converter handles the translation. The header row becomes the element name vocabulary; each data row becomes a configuration record.
Handling tricky CSV inputs
A few patterns trip up naive CSV parsers but are handled correctly here:
- Commas inside quoted fields —
"Smith, John"is one field, not two. - Newlines inside quoted fields — a cell can contain a line break if the whole field is quoted. The RFC 4180 parser handles this; the resulting XML wraps the multi-line value inside the element as-is.
- Doubled quotes inside quoted fields —
""inside a quoted field decodes to a single". This is the RFC 4180 escaping rule, distinct from backslash escaping. - Empty cells — produce an empty element, for example
<city></city>, which is valid XML.
Tag name sanitisation rules
XML element names cannot start with a digit, cannot contain spaces, and cannot include characters like &, <, >, or ". The tool converts any problematic header character to an underscore and adds a leading _ if the first character is a digit. For example, the header 1st name becomes _1st_name. If your XML consumer needs exact tag names, clean the CSV headers before converting.