Flatten XML to CSV with Swift XML Converter

Swift XML Converter supports a "Flatten" operation which allows you to flatten XML data and export to a format like CSV or Excel. The Flatten operation is performed by correctly linking parent and child elements. This ensures that when a parent elements has multiple child elements, the rows are properly linked but could lead to counter-intuitive results because the parent row is repeated for each child row. This HOWTO shows you how you can easily flatten XML data and export to CSV or Excel.

  • Import the XML to be flattened into Swift XML Converter as explained here.

    Data Preview after importing XML
			       into Swift XML Converter

  • Right-click in the "Tables" panel to the left and select "Flatten".

    Flattening XML is as simple as
			       invoking a menu item in Swift XML
			       Converter

  • Depending on the size of the data and the complexity of the XML, the "Flatten" operation could take some time. Unfortunately there is no way to estimate before-hand how long the operation could take so it might appear that the software is doing nothing (or hanged). However in most cases it should be done in a few seconds.

    XML data has been flattened in
			       Swift XML Converter

  • The XML import operation links parent and child rows using foreign keys which are created automatically when parsing the XML. When flattening this data, data in the parent row is repeated for each row of child data for a proper flat view of the XML data. This is illustrated in the screen shots below. The Customer row for "BLAUS" is linked to multiple orders placed by that customer in the Orders table. The data for the parent row is repeated for each row of the child.

    Illustrating the data in the
			       parent row before the Flatten
			       operation. Data in the parent and child rows
			       has been combined during the Flatten
			       operation in Swift XML
			       Converter.

  • The example rows are show here in more detail: the parent row on the left, the corresponding child rows on the right. The bottom image shows the flattened data with parent and child rows combined in the Flatten operation.

    A sample parent row shown in Swift XML
     Converter Sample child rows corresponding to the parent row in Swift
     XML Converter

    Flattened XML data with parent and child rows properly
     combined shown in Swift XML Converter

  • The XML corresponding to the data above is shown below so you can get an idea of the parent-child row linking at work.

    Parent and child elements in XML which have been flattened
     in Swift XML Converter.

    Detailed look at parent and child elements in XML which have
     been flattened in Swift XML Converter.

  • Let us now export the Flattened XML Data to CSV. In the view with the flattened data, right-click and select "Export to CSV". Of course you can also export to Excel from here directly.

    Export Flattened XML data to CSV
			       in Swift XML Converter.

  • In the CSV Export window, select the location where the output file is to be created, select the output encoding (UTF-8, UTF-16, ANSI, etc) and click Next.

    Export Flattened XML data to CSV
			       in Swift XML Converter

  • Saving the Flattened XML Data to CSV. The operation could take some time if the data is large. Click Finish the view the data in an external application such as Excel.

    Saving CSV data in Swift XML
			       Converter.

  • Here we view the exported CSV data in Excel. We see the same data we previewed earlier with the parent and child rows linked properly.

    Data exported as CSV from Swift
			       XML Converter viewed in Excel.

  • This Howto showed how to Flatten XML data and export the data to CSV. In a further article, we will see how to apply queries to the Flattened XML data so as to export a required subset.

Argon DataViz

Create Pivot Tables and Pivot Charts from Large Datasets.

Swift XML Converter

Query & extract XML data into Microsoft Excel (XLS), Microsoft Access (MDB or ACCDB), or CSV.

Exult Standard

Convert XML into Microsoft Excel (XLS), Microsoft Access (MDB or ACCDB), or CSV.

Exult SQL Server

Shred and import XML into SQL Server.

Exult MySQL

Import XML data into automatically created MySQL tables.

Exult Oracle

Import XML into Oracle.