The complete guide

XML to CSV: the complete guide

The XML format, the CSV output, and how to handle real-world documents.

Try the Converter

How is XML structured?

XML is a tree of nested elements, each with optional attributes and text content. A document always has exactly one root element; everything else is a descendant of the root. Here's a minimal example:

<?xml version="1.0" encoding="UTF-8"?>
<catalog>
  <book id="1">
    <title>The Pragmatic Programmer</title>
    <author>Andy Hunt</author>
    <year>1999</year>
    <price>42.50</price>
  </book>
  <book id="2">
    <title>Clean Code</title>
    <author>Robert Martin</author>
    <year>2008</year>
    <price>38.00</price>
  </book>
</catalog>

The tree structure is what makes XML powerful — you can represent arbitrary relationships — but it's also what makes it hard to fit into a flat spreadsheet. The conversion collapses the tree into rows and columns.

How is the "row element" chosen?

Every XML to CSV conversion has to pick a "row element" — the element whose repeated instances become the rows of the CSV. The converter auto-detects this by looking for the most common direct child of the root element. In the example above, <book> is the obvious choice because <catalog> has two <book> children.

Sometimes the choice isn't obvious. An RSS feed has a single <channel> with many <item> children — the items are the rows. A SOAP response may have a single root with nested arrays — the deepest repeating element is usually the row. If auto-detect picks the wrong element, override it in the settings.

Common row element names to expect: item, entry, row, record, product, order, customer, user. If your XML uses something obscure, just type the element name in settings.

How are attributes handled?

XML attributes are key-value pairs on the opening tag of an element, like <book id="1"> where id is the attribute. They are first-class in XML and often carry the most important identifiers (IDs, types, references).

By default, attributes are included as columns prefixed with @. The example above becomes:

@id,title,author,year,price
1,The Pragmatic Programmer,Andy Hunt,1999,42.50
2,Clean Code,Robert Martin,2008,38.00

The @ prefix makes attributes visually distinct from child elements, especially when an attribute and a child element share the same name (which is legal in XML). You can change the prefix to anything you like in settings, or disable attribute inclusion entirely.

How are nested elements flattened?

When a row element contains nested children, those become columns. By default, nesting is flattened with a separator — <address><city>NYC</city></address> becomes the column address__city. The separator is configurable (__, ., /, etc.).

For deeper nesting, the rule applies recursively: <author><name><first>Andy</first><last>Hunt</last></name></author> becomes author__name__first and author__name__last. If a column name gets unwieldy, you can also use a "concatenate" strategy that joins all leaf values into a single column per row.

What about XML namespaces?

Namespaces are XML's way of avoiding element name collisions — <ns:title> and <atom:title> can coexist in the same document. By default, the converter strips namespace prefixes for cleaner column names (title instead of ns:title). If you need the prefix preserved, enable it in settings.

SOAP responses are heavily namespaced (<soap:Envelope>, <soap:Body>, etc.). The converter handles them without special configuration — the prefixes are stripped, and the underlying element names become the column names.

Common XML formats

These formats all work out of the box with auto-detect:

  • RSS 2.0: <rss><channel><item>...</item></channel></rss> — row element is item, columns include title, link, description, pubDate.
  • Atom 1.0: <feed><entry>...</entry></feed> — row element is entry, columns include title, updated, summary, author/name.
  • SOAP responses: <soap:Envelope><soap:Body><GetProductsResponse><Product>...</Product></GetProductsResponse></soap:Body></soap:Envelope> — the deepest repeating element is auto-detected as the row.
  • Sitemaps: <urlset><url>...</url></urlset> — row element is url, columns include loc, lastmod, changefreq, priority.
  • SVG: <svg><path>...</path></svg> — useful for extracting geometry data from vector graphics.
  • KML (geographic): <kml><Placemark>...</Placemark></kml> — row element is Placemark, columns include name, description, and Point/coordinates.

Common edge cases

Real-world XML is rarely as tidy as the textbook example. Here are the most common gotchas and how the converter handles them:

  • Mixed content (text + child elements): <p>Hello <em>world</em>!</p> — the text is concatenated and the child element is added as a separate column.
  • Repeated children with the same name: <person><phone>555-1234</phone><phone>555-5678</phone></person> — joined with a delimiter (default | ) into a single phone column.
  • Empty elements: <description></description> — output as an empty cell.
  • Self-closing tags: <br/> — output as an empty cell or, if attributes are present, an @attr column.
  • CDATA sections: <![CDATA[<raw html>]]> — the raw content is preserved as the cell value, with the angle brackets escaped for CSV.
  • XML declaration and DOCTYPE: Stripped before parsing. The <?xml ?> header and any <!DOCTYPE> declarations are removed automatically.
  • Namespaces in tags: <ns:title xmlns:ns="..."> — the prefix is stripped (or preserved, per settings) and the local name is used as the column header.
  • Comments and processing instructions: Stripped before parsing. Comments (<!-- -->) and processing instructions (<? ?>) are ignored.
Tools for this job

The same job, the way you need it

Free tools for the specific version of this conversion you are actually doing.

XML to CSV for RSS feeds

Turn a feed into rows - RSS 2.0 and Atom, with the Python that reads both.

FAQ

Frequently asked questions

What is an XML to CSV converter?
An XML to CSV converter parses a well-formed XML document and produces a CSV file where each repeating element becomes one row and each child element or attribute becomes a column. XML's hierarchy is flattened into a table that opens directly in Excel or Google Sheets.
Is XML to CSV conversion free?
Yes. HopConvert's XML to CSV converter is 100% free with no sign-up required. There are no paid tiers, no feature gates, and no premium plans. Parsing happens in your browser so we don't pay for servers and we don't charge you.
Which XML element becomes the row?
The converter auto-detects the most common repeating direct child of the root element. For RSS feeds that's item, for SOAP responses it's the operation-specific element, for arbitrary XML it's whichever child element appears most often. You can override the choice in settings.
Does the converter work with RSS and Atom feeds?
Yes. RSS 2.0 and Atom 1.0 are both well-supported. The auto-detect logic identifies item and entry elements as the row source. Standard fields like title, link, pubDate, and description all become columns.
What about SOAP or API responses?
Yes. SOAP envelopes, REST API responses wrapped in XML, and arbitrary enterprise formats all parse correctly. The auto-detect logic finds the repeating element regardless of namespace prefix.

Try the XML to CSV converter

Free, instant, and private — your XML never leaves this tab.

Open the XML to CSV Converter