CSV to XML Converter
Convert CSV rows into XML. The header row supplies the element names, each data row becomes a <row> element, and special characters are escaped.
What the CSV to XML converter does
It turns a CSV table into an XML 1.0 document with a fixed, predictable layout: a <rows> root element, one <row> element per data row, and inside each row one child element per column, named after the column header. The first CSV row is always treated as the header. CSV quoting is read according to RFC 4180, so values containing the delimiter, quotes or line breaks arrive in the XML intact.
How to use it
- Paste CSV into the CSV Input pane, or use File or URL to load it.
- Set Delimiter to Comma, Semicolon or Tab to match the data.
- Click Convert.
- Use Copy, or Download to save
converted.xml. Clear empties both panes.
Delimiter is the only option. The root and row names, the two-space indentation and the XML declaration are fixed.
Example
sku,product name,price
A1,Desk lamp,29.00
B7,Chair & cushion,149.00
converts to:
<?xml version="1.0" encoding="UTF-8"?>
<rows>
<row>
<sku>A1</sku>
<product_name>Desk lamp</product_name>
<price>29.00</price>
</row>
<row>
<sku>B7</sku>
<product_name>Chair & cushion</product_name>
<price>149.00</price>
</row>
</rows>
The space in product name is not allowed in an element name, so it becomes an underscore, and the ampersand in the data is written as the entity &.
How headers become element names
CSV headers can be any text, but XML element names follow strict rules. Each header is trimmed and then cleaned up like this:
| CSV header | Element name | Why |
|---|---|---|
product name | product_name | Spaces and other punctuation become _ |
a/b | a_b | Same rule; only ASCII letters, digits, _, - and . are kept |
2024 sales | _2024_sales | Names cannot start with a digit, so _ is added |
café | caf_ | Accented and non-Latin letters are replaced too |
xmlns:foo | xmlns_foo | Colons are replaced, so no namespaces are created |
| (empty) | _ | An empty header still needs a name |
Two headers that clean up to the same name, such as a b and a_b, both produce <a_b>. That is still well-formed XML, but a schema or a lookup by element name may only see the first.
What happens to the values
&,<and>are escaped as entities. Double quotes are left as they are, which is valid inside element text.- Control characters other than tab and line breaks are removed, because XML 1.0 does not allow them even as entities.
- A line break inside a quoted value is kept as a real line break inside the element.
- Empty and missing cells become empty elements such as
<price></price>; values beyond the last header are dropped. - Every value is element text. There is no option to output attributes or typed values.
When converting CSV to XML is useful
- Imports that only accept XML — some ERP, accounting and e-commerce systems take XML files; a spreadsheet export converted here gives you a starting point to map onto their format.
- XSLT pipelines — once tabular data is in XML you can sort, filter or reshape it with an XSLT stylesheet or query it with XPath.
- Test fixtures — turning a small spreadsheet of test cases into XML is quicker than typing the markup by hand.
If the system you are feeding accepts JSON as well, CSV to JSON is usually simpler to work with, because it does not need any header renaming.
Common problems and fixes
| Symptom | Cause | Fix |
|---|---|---|
One element per row with a name like id_name_price | Wrong delimiter, so the whole header line is read as one column. | Change Delimiter; the CSV Formatter can detect it for you. |
| Error saying a quoted field is never closed | An opening " without a closing one. | Correct the line given in the message. |
The XML has <rows> but no <row> | The input has only a header row. | Add data rows below the header. |
| Your importer expects other element names | The names are fixed by the tool. | Rename the headers in the CSV, or use find and replace on <rows> and <row>. |
Frequently asked questions
Can I choose the root and row element names?
Not in the tool. The output always uses <rows> and <row>. A find and replace on those two tags is safe, because data values are escaped and cannot contain a literal <row> — unless one of your column headers is itself row or rows.
Can columns become attributes instead of child elements?
No, every column becomes a child element. If you need attributes, an XSLT stylesheet or a short script can move selected children into attributes after conversion.
Will the result validate against my XSD?
The output is well-formed, but whether it is valid depends on your schema. Element order follows the CSV column order, so reorder the columns to match a schema that uses xs:sequence.
How do I check or re-indent the output?
Paste it into the XML Formatter to check that it is well-formed, change the indentation or minify it. To read it back into a table, use XML to CSV, which turns each <row> back into a CSV line.
Is my data uploaded?
No. The conversion is plain JavaScript running in your browser and nothing is sent to a server. Only the URL button makes a request, and it goes from your browser to the address you enter.