XML to CSV

Extract a table from repeated XML elements.

Input
XML input
Output
Result

About this tool


To build a table from XML you first have to decide which element represents a row. This converter looks for the repeated element in the document (the <book> inside <catalog>, the <record> inside <records>), and uses each occurrence as one row.

That inference is the whole difficulty of the conversion. An XML document with no repeated element has no rows to extract, and the tool says so rather than emitting a single wide row that looks like a mistake.

How to use it

  1. Paste or upload XMLDrop a .xml file onto the input pane, use the file picker, or paste the text directly.
  2. Adjust the options if neededThe defaults suit most input. Open Options to change how values are interpreted or formatted.
  3. ConvertPress Convert to CSV, or use Ctrl+Enter (Cmd+Enter on macOS).
  4. Read any warningsWarnings explain anything that could not be represented exactly in the target format.
  5. Copy or downloadCopy the result, or download it as a .csv file.

Worked examples


Each example below is executed against this tool by the test suite, so what you see is what the tool actually produces.

XML to CSV

Input

<catalog>
  <book id="1"><title>XML Basics</title></book>
  <book id="2"><title>Advanced XML</title></book>
</catalog>

Output

title,@_id
XML Basics,1
Advanced XML,2

The repeated <book> element became the rows; the id attribute became an @_id column.

What to watch for


The details that decide whether a conversion is correct, and where information can be lost without any error being raised.

How the row element is chosen
The document is walked looking for the first element that appears more than once at the same level with object-like content. That is nearly always the intended row. If your document nests several repeated elements, the outermost is used, extract the inner fragment yourself if you need a different one.
Nested elements become dotted columns
Child elements inside a row are flattened into dotted names, so an <author><name> inside <book> becomes the column author.name. Attributes appear as columns prefixed with @_, keeping them distinct from child elements of the same name.
Rows with different children still line up
The header is the union of every field seen across all rows, so a row missing an element simply gets an empty cell. No row is ever shorter than the header, which keeps the file valid for strict parsers.
What cannot be represented
Mixed content, comments and namespace semantics are all lost. A repeated child element inside a single row has no column form and is serialised as text. Types disappear entirely, since both XML content and CSV cells are untyped text.

Limitations


  • Requires a repeated element; documents without one cannot be tabulated.
  • The row element is inferred rather than chosen explicitly.
  • Mixed content, comments and namespace semantics are lost.
  • Processing happens in your browser, so very large inputs are bounded by available memory. Files above roughly 10 MB are handled but will feel slower, and multi-hundred-megabyte files are better suited to a command-line tool.

Questions


Why does my XML fail to convert?
There is no repeated element to use as rows. CSV needs a list; a document of unique nested sections has no table form. Check that the element you expect to repeat actually occurs more than once.
Why are some columns prefixed with @_?
Those came from XML attributes. The prefix keeps them distinct from child elements, which could otherwise share the same name.
Can I choose which element becomes a row?
Not directly. The outermost repeated element is used. To target a different one, paste just that fragment of the document.