Format Code Now
/
ConvertCSV to XML Next: CSV to YAML ›

CSV to XML Converter

CV-07

Paste CSV and get XML with one element per row and one child element per column, named from the header row. Quoted commas, quotes and line breaks are read correctly.

Runs in your browser. Nothing is uploaded.

CSV (optional first lines: -- root: name, -- row: name)

XML

How to use it

  1. Paste your CSV into the input box, or open a .csv file (up to 5 MB) or drop it on the box.
  2. Leave Delimiter on Auto, or choose comma, semicolon, tab or pipe. Untick First row is header if there is none.
  3. Choose the root and row element names, the indent, and whether to keep the XML declaration.
  4. Copy the XML or download it as an .xml file.

How rows and columns become elements

The first row supplies the column names. Each later row becomes a row element, and each cell becomes a child element named after its column. A CSV with the header id,name,city gives <row><id>1</id><name>Ada</name><city>London</city></row>. Without a header row the columns are named column_1, column_2 and so on. All values are written as text, with no types, and nothing is written as an attribute.

Element names and escaping

Header text is not always a legal XML name. Characters that XML does not allow, such as spaces, are replaced with an underscore, a name that starts with a digit gets a leading underscore, and repeated names get _2, _3. Empty cells become empty elements. The characters & < > in your data are escaped, and a control character XML 1.0 cannot hold is reported as an error with its row and column.

Choosing the root and row names

The lists offer common names such as rows, data and records for the root, and row, record and item for each row. To use your own, put -- root: orders and -- row: order on the first lines of the input. Those lines are read as settings and are not part of the data. The names must be valid XML names, and the converter tells you if they are not.

Error messages and what to do

MessageWhat it meansFix
A quoted field is never closed (missing closing ")A field starts with a double quote, but the text ends before the closing quote, so the parser cannot tell where the field stops.Add the missing closing quote, or double any quote that belongs inside the text, as in "".
Row 1, column "a" contains a control character that XML 1.0 cannot holdA cell holds a character such as a null or a bell that is not allowed in an XML 1.0 document.Remove the character from that cell in the CSV.
No rows found in the CSV.The input has no rows after blank lines and settings lines are removed.Paste the CSV data.

Questions people ask

How do I convert CSV to XML?

Paste the CSV into the input box. Each row becomes a row element and each column becomes a child element named from the header. Copy the result or download it as an .xml file. Nothing is uploaded.

How do I choose the root and row element names?

Pick from the Root element and Row element lists, or put -- root: name and -- row: name on the first lines of the input to use your own. Those lines are settings, not data, and the names must be valid XML names.

What happens to headers with spaces or symbols?

XML element names cannot contain spaces, so characters XML does not allow are replaced with an underscore. A header such as first name becomes first_name, and one that starts with a digit gets a leading underscore. Repeated names get _2, _3.

Can I convert CSV to XML attributes instead of elements?

No. Every column becomes a child element. If you need attributes, convert the CSV to JSON, rename the keys with a leading @ and use the JSON to XML tool, where keys that start with @ become attributes.

How are empty cells written?

An empty cell becomes an empty element such as <city/>, and a row that has fewer cells than the header is padded with empty elements. The converter never leaves a column out, so every row element has the same children.

Does it work without a header row?

Yes. Untick First row is header and the columns are named column_1, column_2 and so on, with every CSV row written as a row element. Short rows are padded with empty elements.

About this tool

Each row becomes a row element and each column becomes a child element named after the header. Header names that are not valid XML names have invalid characters replaced with _ (a name starting with a digit gets a leading _), and duplicates get _2, _3. Without a header row the columns are named column_1, column_2 and so on. Empty cells become empty elements, and short rows are padded with empty elements. Text is escaped (& < >), and control characters XML 1.0 cannot hold are an error. All values are text, with no types. To set the names yourself, put -- root: orders and -- row: order on the first lines of the input; they override the lists. It does not write attributes.

Format Code Now: free, no ads, no accounts. Your input stays in your browser.