XML to CSV in Excel: Complete Tutorial

Microsoft Excel can turn structured XML into a table, but the import route matters. XML Maps connect schema elements to worksheet cells, while Power Query lets you expand nested tables before loading them. Both approaches can produce a CSV, provided you decide which XML elements represent rows and verify the imported values before saving.

These instructions apply to Windows desktop Excel 2019, Excel 2021, and Microsoft 365. Ribbon labels can vary slightly with updates. Excel for the web and Mac versions have different XML capabilities and are outside this tutorial's scope. For a quick local alternative without workbook setup, use the online XML to CSV converter.

Method 1: Import XML as Table

Step 1: Open Excel

  1. Start a blank workbook in the Windows desktop application. Save a working copy as an Excel workbook so later CSV export does not become your only copy.
  2. Open File, Options, and Customize Ribbon. In the list of main tabs, enable Developer and confirm with OK.
  3. Return to the workbook and select Developer. The XML commands are grouped on that ribbon tab.

The Developer tab is needed for XML Maps, not for the Power Query route described later. Keep your original XML unchanged. If the document is confidential, store the working copy in an approved local location and check whether your organization's workbook or cloud synchronization settings meet its data handling requirements.

Step 2: Use Developer Source and XML Maps

  1. On Developer, select Source to open the XML Source task pane, usually at the right side of the window.
  2. In the task pane, choose XML Maps, then Add.
  3. Select an XSD schema if your data provider supplies one. Otherwise select the XML file and let Excel attempt to infer a schema.
  4. Review the resulting hierarchy before assigning any nodes to the worksheet.

An inferred map is based on the selected sample. Optional fields absent from that sample may not be represented as expected. Complex repeating structures, mixed content, or schema features unsupported by Excel can prevent a useful map. A message about inferring a schema is not a guarantee that every relationship has been preserved. Inspect the tree and compare it with known source records.

Step 3: Select Your XML Fields

  1. In XML Source, identify the repeating element that corresponds to one intended business row.
  2. Drag compatible mapped elements onto the worksheet. Excel creates mapped cells or a table depending on the selected structure.
  3. Include identifier attributes as well as element values when the map exposes them.
  4. Place unrelated repeating groups in separate tables when a single flat table would misrepresent their relationship.

A catalog with one title and price per book is easier to map than an order containing repeated items and repeated discounts. Decide whether you want one row per order, item, or relationship. If the map cannot express that decision clearly, switch to Power Query or the nested XML converter rather than forcing unrelated values into the same row.

Step 4: Review and Import

  1. Choose Developer, Import, and select the XML file to populate the mapped worksheet.
  2. Confirm the target location if Excel asks where to place the data.
  3. Compare the first, middle, and last records against the source. Count rows and check optional fields.
  4. Review identifiers, dates, decimal values, and text containing punctuation or international characters.

Excel may interpret values as numbers or dates. A product code with leading zeroes can become a shorter number, and a long identifier can lose precision. Formatting an already changed number as text does not restore the original digits. Reimport with appropriate types or use a workflow that preserves those fields as text from the beginning.

Step 5: Save as CSV

  1. Make the intended output worksheet active.
  2. Choose File, Save As, and select CSV UTF-8 (Comma delimited) (*.csv).
  3. Select a separate output filename and confirm the format notice.
  4. Keep the workbook version as well if you need maps, transformations, formatting, or additional worksheets.

CSV exports the active worksheet only. It does not retain formulas as workbook logic, multiple sheets, cell formatting, or the XML hierarchy. The named UTF-8 format does not directly promise a tab, semicolon, or pipe delimiter for every regional setup. Inspect the actual exported file and use a dedicated converter when the destination requires a specific delimiter.

Method 2: Using Power Query

Accessing Power Query

  1. Open Data, then Get Data, From File, and From XML.
  2. Select the XML document. Review the Navigator or preview window that appears.
  3. Choose Transform Data to open Power Query Editor rather than immediately loading an unfamiliar structure.
  4. Inspect column names, nested values, and the Applied Steps pane before changing the table.

Power Query makes transformations repeatable. Each expansion and type conversion appears as a step that you can review or remove. That is useful for recurring feeds, but a saved query still assumes a particular source structure. A supplier adding a wrapper or changing a namespace may require adjustments before the next refresh produces correct results.

Transforming XML Data

  1. Locate Table or Record cells containing your intended records. Use the expand control in the column header.
  2. Select the child fields you need and keep prefixes when they help distinguish similarly named elements.
  3. Repeat expansion for deeper levels, reviewing row counts after each step.
  4. Remove unnecessary columns and assign types deliberately. Keep identifiers as Text when numeric interpretation would change them.
  5. Review any automatically inserted Changed Type step and replace it if it conflicts with the source contract.

Expanding a repeated child table can duplicate parent values across several rows. Expanding a second independent repeated group can multiply that row count again. This behavior may be correct, but it should be intentional. Check a source record with known child counts. Do not assume that two repeated lists correspond by position unless the data provider explicitly defines that relationship.

Exporting to CSV

  1. Choose Home, Close & Load in Power Query Editor to create the worksheet table.
  2. Review the loaded values and ensure the intended sheet is active.
  3. Use File, Save As, CSV UTF-8 (Comma delimited) (*.csv).
  4. Reopen the CSV through Data import in a separate workbook and confirm representative values.

A CSV is a snapshot of the query result at the time it was saved. Refreshing the workbook later does not automatically update an unrelated CSV copy unless you build additional automation. Keep file naming and refresh procedures clear so colleagues know which export is current and which source or query produced it.

Limitations of the Excel Method

XML is hierarchical and Excel worksheets are rectangular. Some structures cannot be represented by a simple XML Map, and complex nested collections may require several Power Query steps. Worksheet row limits and available memory also apply. A file that is modest in bytes can expand into many rows if it contains independent repeated groups.

Excel's automatic value interpretation is useful for analysis but risky for exact identifiers. Dates depend on regional settings, large numbers can lose precision, and leading zeroes can disappear. If the CSV must reproduce text exactly, validate the import types and compare strings against the source before saving. Consider a tested script for recurring exact exports.

Troubleshooting Common Issues

Cannot Open the File

Confirm that the file is valid XML and that its encoding matches its declaration. Open a copy in an XML-aware editor or use the XML parser to locate syntax errors. Fix the source rather than repeatedly changing the file extension. A CSV extension on XML does not perform a conversion.

Missing Data After Import

Check whether the selected record path and expansions include the missing values. Optional fields can be absent from the first sample used for inference. Attributes may also need separate selection. Compare records near the end of the source, and inspect whether a filter or navigation step removed rows unexpectedly.

Incorrect Column Mapping

Review namespace distinctions and repeated groups. Similar local names can refer to different fields, and repeated data may not fit one table. Remove the problematic transformation step and rebuild it with a clear row definition. Verify the result with a small representative sample before refreshing the complete file.

When to Use an Online Converter

For occasional conversion, a browser tool avoids ribbon setup and makes field selection visible immediately. The free XML to CSV converter supports custom delimiters, nested expansion, and a preview before download. Keep spreadsheet formula protection enabled for untrusted input and inspect identifiers after importing the result into Excel.

For recurring workbook analysis, Power Query can be a good fit because transformations remain documented as steps. For complex automation, Python gives finer control over validation and output. Whichever method you choose, preserve the source, decide what a row means, and verify the saved CSV as a separate artifact.

Related Guides