August 15, 2026
Flattening Nested and Repeated XML Elements to CSV
Flattening XML to CSV works cleanly when each record is a flat list of simple fields — but nested child elements need dot-notated column names, and repeated elements within a single record (like multiple <tag> elements inside one <product>) have to be joined into a single cell, since a CSV cell can't hold more than one value.

Nested elements: dot notation, same as JSON
<product><name>Widget</name><price><amount>19.99</amount><currency>USD</currency></price></product> flattens into three columns: name, price.amount, and price.currency — the same dot-notation convention used for nested JSON, since both are solving the identical problem of representing hierarchy in a flat grid.
Repeated elements within one record: the harder case
If a single <product> contains multiple <tag> elements, there's no clean column-per-tag answer unless every record has exactly the same number of tags — a converter typically joins them into one cell ("electronics; sale; new"), which is readable but means that cell's individual values aren't directly queryable as separate columns without re-splitting the string later.
Records with inconsistent fields
If some records include an optional element that others omit, a correct converter needs a column for every field seen across the entire document — with blank cells for records missing it. A naive converter that only looks at the first record's structure will silently misalign every column starting at the first record where the pattern differs.
Want to try this yourself?
Open XML to CSV →