CSV ↔ XML Converter Online
Convert CSV data to XML and XML back to CSV instantly in your browser.
When a CSV ↔ XML converter is the right tool
Use this page to wrap a headered CSV table in a simple XML document, or to flatten a list of similar child elements back into CSV. Choose a direction, paste the source, and click Convert. In the CSV → XML direction you can also name the root and row elements. The result does not update as you type.
The XML it writes is deliberately flat: one element per column, all values as text. It is the wrong tool for documents with attributes, mixed content, or real nesting — use XML ↔ JSON when you need a more structured conversion, or XML Formatter to pretty-print a document you already have.
Use cases
Wrapping a spreadsheet export in XML
Leave the direction on CSV → XML, paste a header row and the rows beneath it, and Convert. Load Sample uses a short name, age, city, and active table. You can change the default records / record names before you convert, for example to users / user.
Flattening a list of elements back to CSV
Switch to XML → CSV and paste a document whose root’s children are the rows you care about. Tag names on those children become the header. This works for the XML this page emits, and for similarly flat lists. Nested children and attributes will not be represented faithfully.
Characters that need escaping
A company name such as Bob & Co is written as Bob & Co in the XML. Quoted commas in the CSV survive as a single cell. Those are the cases this converter is meant to handle.
How conversion works
CSV → XML trims the text, drops empty lines, parses rows with a quoted-comma splitter, and writes an XML declaration plus the root, one row element per record, and one child element per header. XML → CSV parses with DOMParser and application/xml, takes the root’s children as rows, unions their direct child tag names as headers, and fills each cell with querySelector on that tag name, which returns the first descendant match. Switching direction clears the editors but keeps the element names.
name,age,city
Alice,30,New York
Bob & Co,25,London
<?xml version="1.0" encoding="UTF-8"?>
<records>
<record>
<name>Alice</name>
<age>30</age>
<city>New York</city>
</record>
<record>
<name>Bob & Co</name>
<age>25</age>
<city>London</city>
</record>
</records>age stays character data, not a number. The ampersand in the second name is escaped. That is expected: this converter does not guess types.
full name,
Alice,
becomes tags <full_name> and <col1>.Spaces become underscores. A blank header becomes col1 (zero-based). The tool does not otherwise sanitize names, so unusual headers can yield invalid XML.
What this tool does not do
It does not model attributes, namespaces, comments, or nested tables, and it does not check that the tags it writes are valid. It does not update live, and it does not upload anything. For column statistics on the CSV side, use CSV Column Stats. For a typed YAML list, use CSV ↔ YAML.
How to use CSV ↔ XML Converter
- Choose CSV → XML or XML → CSV. Switching tabs clears the input.
- For CSV → XML, optionally set the root and row element names.
- Paste the source, or use Load Sample for a short example in the current direction.
- Click Convert, then Copy when the output looks right.
Frequently asked questions
How does CSV → XML work?
The first line is the header. Each later row becomes a child of the root element. Header text is trimmed, runs of whitespace become underscores, and an empty header becomes col0, col1, and so on. Cell text is escaped for &, <, >, and ". Values stay text — there is no type inference. You can edit the root and row element names (they default to records and record). Empty names fall back to those defaults. Changing the names after Convert does not rebuild the output until you convert again.
How does XML → CSV work?
The browser’s DOMParser reads the text as XML. A parse error is shown as Invalid XML plus up to 100 characters of the parser message. Direct children of the root element become rows. Column names are the union of those children’s own tag names. Each cell is the text of the first match of that tag under the row, so a nested element with the same name can be picked instead of the direct child. Attributes are ignored. If the root has no child elements, the tool reports that none were found.
Does this converter handle quoted commas and nested XML?
Quoted commas and doubled quotes are honored when reading CSV, on a single line. The XML this page writes is a flat list of records with one element per column — it does not build nested structures from CSV. On the way back, attributes and really nested documents are not modeled; only element text is exported.
Are element names checked for valid XML?
No, beyond spaces becoming underscores and empty headers becoming colN. A header that starts with a digit, or a root name you type that is not a legal XML Name, can produce output that a strict parser will reject. The root and row name fields appear only in the CSV → XML direction.
Do the results update as I type?
No. You have to click Convert. Switching CSV → XML or XML → CSV clears the input and the output, but it leaves the root and row names as they are. Load Sample pastes a short example for the current direction and clears the output. There is no Swap button.
Is my data sent to a server?
No. Conversion runs in your browser, including the XML parse, which uses the browser’s DOMParser. Closing the tab discards what you pasted. Do not paste documents that contain personal data or secrets if you would not be comfortable with them sitting in memory on this device.
Related tools and guides
References
- Extensible Markup Language (XML) 1.0 defines element names and escaping. This page escapes &, <, >, and quotes in cell text, but it does not validate that the tags it writes are legal Names.
- RFC 4180 describes quoted CSV fields. The reader honors quoted commas on a single line, but it does not reassemble a quoted field that spans lines.