Convert XML to CSV with node path as header

I see a post Convert XML to CSV (with node path as header) using XSLT, the poster have this XML data:

<tXML>
    <Header>
        <Source>XPTO</Source>
        <User_ID>127</User_ID>
        <Message_Type>Ship</Message_Type>
        <Company_ID>105</Company_ID>
        <Msg_Locale>English (United States)</Msg_Locale>
        <Version>2017</Version>
    </Header>
    <Message>
        <Ship>
            <ShipSummary>
                <ComName>XPTO 123</ComName>
                <FacName>6</FacName>
            </ShipSummary>
        </Ship>
    </Message>
</tXML>

He want to convert to CSV like this:

tXML/Header/Source,tXML/Header/User_ID,tXML/Header/Message_Type,tXML/Header/Company_ID,tXML/Header/Msg_Locale,tXML/Header/Version,tXML/Message/Ship/ShipSummary/ComName,tXML/Message/Ship/ShipSummary/FacName
XPTO,127,Ship,105,English (United States),2017,XPTO 123,6

I don’t like using XSLT, I like my tool Data File Converter, so I test, it can do this, in a minute.

1. Open XML file, set XML options.

Convert XML to CSV with node path as header - set XML

2. set CSV options.

Convert XML to CSV with node path as header - set CSV

3. “Next” and “Next”, convert, get output CSV file.

XML → CSV reference

Type mapping

Value kindin XMLin CSV
Int<int>1234</int>1234
Bigint<bigint>9007199254740993</bigint>9007199254740993
Decimal<decimal>1234.56</decimal>1234.56
Float<float>1.234e10</float>1.234e+10
Text<char>text</char>quoted only when it contains a comma or a quote
Long text<text>multi-line text</text> (entities for &amp; &lt;)must be quoted; line breaks inside force multi-line records
Date<date>2026-09-18</date> (xs:date with an XSD)2026-09-18
Datetime<datetime>2026-09-18T14:30:00Z</datetime> (xs:dateTime)2026-09-18 14:30:00
Binary<blob>base64...</blob> (xs:base64Binary)not representable - base64 or hex string
Boolean<bool>true</bool>TRUE / FALSE, or 1 / 0 depending on the writer
JSONescaped inside an element, or its own sub-treethe whole JSON value quoted, with internal quotes doubled

Dialect differences

Both XML and CSV are file formats, so what differs below is how each one chooses to represent a value.

Propertyin XMLin CSV
identifiersAttribute values in quotes; entities (&amp; &lt; &gt;) for ...Double quotes; a literal quote is doubled ("" )
datesText (xs:date / xs:dateTime when an XSD is in play)Conventional text: 2026-09-18 or 2026-09-18 14:30:00
binarybase64Binary / hexBinary inside textNot supported
separatorTags, not delimitersComma ","
encodingDeclared in the XML declarationNo declaration - UTF-8 works only with a BOM
typingNone in the markup itselfNone - every field is text
shapeArbitrary treeFlat table, optional header row
ceilingWhole document is usually parsed into memoryNo formal limit; row count bounded by memory

Convert your data online, free

Free in-browser converters for CSV, Excel, JSON, XML and SQL: Withdata Online Data Conversion. Large files, batch conversion or scheduling? See the offline desktop apps, or browse all data conversion tools.


Posted

in

by

Tags: