CSV to XML Converter

Turn a CSV table into well-formed, indented XML. Each data row becomes a record element under a configurable root, and you choose whether columns map to child elements (<name>Ana</name>) or attributes (<row name="Ana"/>). The parser handles quoted fields with embedded commas, quotes, and newlines, and all five XML special characters are escaped, so the output is valid XML you can feed straight into an XSLT, a SOAP body, or a config file.

How to use the CSV to XML Converter

Paste CSV with a header row (the first row supplies the element or attribute names). The converter emits an XML document whose root is the Root element name, with one Record element per data row. Set Columns as to Child elements to nest each column as a sub-element, or to Attributes to place each column as an attribute on the record element — useful when values are short identifiers.

If your CSV has no header, tick No header row and columns are named col1, col2, and so on. Pick the delimiter that matches your file (comma, semicolon, or tab). Column names are sanitised into valid XML names — spaces become underscores and a leading digit is prefixed — because XML element and attribute names cannot start with a number or contain whitespace. The output is pretty-printed with two-space indentation and every value is XML-escaped, so &, <, >, and quotes survive intact. Use Download .xml to save it.

What is the CSV to XML Converter?

Going from CSV to XML means adding structure that a flat file does not carry. A CSV is just rows of delimited fields; XML wants a single root element, a repeating record element, and a name for every value. The first design decision is element-vs-attribute modeling. XML can represent the same data two ways: as nested child elements, which are verbose but extensible (a child can later gain its own children or attributes), or as attributes on the record element, which are compact but cannot repeat or contain markup. A common rule of thumb is "data as elements, metadata as attributes" — IDs, types, and flags make good attributes, while the substantive field values are usually elements. This tool lets you pick per-conversion so you can match whatever schema or consumer you are targeting.

The second concern is correctness of the names and the values. XML names have rules that CSV headers ignore: they cannot contain spaces, cannot start with a digit, and a handful of characters are reserved. The converter sanitises each header into a legal name (spaces to underscores, a leading digit prefixed with an underscore) so the document is well-formed even when your spreadsheet column is called 2024 Total ($). Reading the CSV correctly matters too: a field like "Smith, John" or one containing a newline is a single value, not two columns, so the parser tracks quote state and unescapes doubled quotes (""") exactly as RFC 4180 specifies.

Finally, every emitted value is entity-escaped. The five predefined XML entities — &amp;, &lt;, &gt;, &quot;, and &apos; — are substituted for &, <, >, ", and ' so that text containing markup-like characters or ampersands does not break the document. Attribute values are quote-escaped as well, which is essential in attribute mode. For the reverse direction, or to round-trip data back to a table, see the XML to CSV converter.

Common use cases

  • Feeding XML-only systems — convert a spreadsheet export into the XML payload an older API, ERP, or SOAP service expects.
  • Generating config or seed files — maintain data as CSV and emit XML configuration (menus, lookup tables, fixtures) on demand.
  • XSLT and report pipelines — produce XML input so you can transform tabular data with stylesheets into HTML or PDF.
  • Sitemaps and feeds — turn a list of URLs or items in CSV into the repeating-element XML structure those formats use.
  • Test data for XML parsers — quickly fabricate well-formed XML documents of arbitrary width and depth from a CSV mockup.
  • Data interchange with partners — deliver an XML version of a dataset to a counterparty whose ingestion only accepts XML.

Frequently asked questions

Should I map columns to elements or attributes?

Use child elements for substantive field values that might grow more structure later, and attributes for short metadata like IDs, types, or flags. Attributes are more compact but cannot repeat or hold nested markup. The tool lets you switch between the two with the "Columns as" selector.

What happens to commas or quotes inside a field?

The CSV parser is RFC 4180 aware: a quoted field can contain the delimiter, line breaks, and escaped double quotes (written as ""). Those are read as a single value, then XML-escaped in the output rather than splitting the row.

How are invalid XML element names handled?

Header names are sanitised into legal XML names — spaces and illegal characters become underscores, and a name starting with a digit is prefixed with an underscore — because XML names cannot contain whitespace or begin with a number.

Is the output indented?

Yes. The XML is pretty-printed with two-space indentation and a standard XML declaration, so it is readable and ready to paste into an editor, request body, or file.

Does the conversion run on a server?

No. Parsing and XML generation happen entirely in your browser, so your CSV never leaves the page — safe for confidential data.