{"id":22479,"date":"2024-10-18T03:53:06","date_gmt":"2024-10-18T03:53:06","guid":{"rendered":"http:\/\/www.withdata.com\/blog\/?p=22479"},"modified":"2024-11-25T03:46:20","modified_gmt":"2024-11-25T03:46:20","slug":"convert-xml-to-csv-with-node-path-as-header","status":"publish","type":"post","link":"https:\/\/www.withdata.com\/blog\/use\/convert-xml-to-csv-with-node-path-as-header.html","title":{"rendered":"Convert XML to CSV with node path as header"},"content":{"rendered":"<p>I see a post <a href=\"https:\/\/stackoverflow.com\/questions\/71069555\/convert-xml-to-csv-with-node-path-as-header-using-xslt\">Convert XML to CSV (with node path as header) using XSLT<\/a>, the poster have this XML data:<\/p>\n<pre>&lt;tXML&gt;\r\n    &lt;Header&gt;\r\n        &lt;Source&gt;XPTO&lt;\/Source&gt;\r\n        &lt;User_ID&gt;127&lt;\/User_ID&gt;\r\n        &lt;Message_Type&gt;Ship&lt;\/Message_Type&gt;\r\n        &lt;Company_ID&gt;105&lt;\/Company_ID&gt;\r\n        &lt;Msg_Locale&gt;English (United States)&lt;\/Msg_Locale&gt;\r\n        &lt;Version&gt;2017&lt;\/Version&gt;\r\n    &lt;\/Header&gt;\r\n    &lt;Message&gt;\r\n        &lt;Ship&gt;\r\n            &lt;ShipSummary&gt;\r\n                &lt;ComName&gt;XPTO 123&lt;\/ComName&gt;\r\n                &lt;FacName&gt;6&lt;\/FacName&gt;\r\n            &lt;\/ShipSummary&gt;\r\n        &lt;\/Ship&gt;\r\n    &lt;\/Message&gt;\r\n&lt;\/tXML&gt;\r\n<\/pre>\n<p>He want to convert to CSV like this:<\/p>\n<pre>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\r\nXPTO,127,Ship,105,English (United States),2017,XPTO 123,6\r\n<\/pre>\n<p>I don&#8217;t like using XSLT, I like my tool <a href=\"https:\/\/www.withdata.com\/data-file-converter\/\">Data File Converter<\/a>, so I test, it can do this, in a minute.<\/p>\n<p>1. Open XML file, set XML options.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.withdata.com\/images\/case\/node_path_as_header_xml.png\" alt=\"Convert XML to CSV with node path as header - set XML\" width=\"722\" height=\"572\" style=\"max-width:100%;height:auto;display:block;\" \/><\/p>\n<p>2. set CSV options.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.withdata.com\/images\/case\/node_path_as_header_csv.png\" alt=\"Convert XML to CSV with node path as header - set CSV\" width=\"722\" height=\"572\" style=\"max-width:100%;height:auto;display:block;\" \/><\/p>\n<p>3. &#8220;Next&#8221; and &#8220;Next&#8221;, convert, get output CSV file.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I see a post Convert XML to CSV (with node path as header) using XSLT, the poster have this XML data: &lt;tXML&gt; &lt;Header&gt; &lt;Source&gt;XPTO&lt;\/Source&gt; &lt;User_ID&gt;127&lt;\/User_ID&gt; &lt;Message_Type&gt;Ship&lt;\/Message_Type&gt; &lt;Company_ID&gt;105&lt;\/Company_ID&gt; &lt;Msg_Locale&gt;English (United States)&lt;\/Msg_Locale&gt; &lt;Version&gt;2017&lt;\/Version&gt; &lt;\/Header&gt; &lt;Message&gt; &lt;Ship&gt; &lt;ShipSummary&gt; &lt;ComName&gt;XPTO 123&lt;\/ComName&gt; &lt;FacName&gt;6&lt;\/FacName&gt; &lt;\/ShipSummary&gt; &lt;\/Ship&gt; &lt;\/Message&gt; &lt;\/tXML&gt; 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 [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3141],"tags":[34,68,1491],"class_list":["post-22479","post","type-post","status-publish","format-standard","hentry","category-use","tag-csv","tag-xml","tag-xml-to-csv"],"_links":{"self":[{"href":"https:\/\/www.withdata.com\/blog\/wp-json\/wp\/v2\/posts\/22479","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.withdata.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.withdata.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.withdata.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.withdata.com\/blog\/wp-json\/wp\/v2\/comments?post=22479"}],"version-history":[{"count":3,"href":"https:\/\/www.withdata.com\/blog\/wp-json\/wp\/v2\/posts\/22479\/revisions"}],"predecessor-version":[{"id":22765,"href":"https:\/\/www.withdata.com\/blog\/wp-json\/wp\/v2\/posts\/22479\/revisions\/22765"}],"wp:attachment":[{"href":"https:\/\/www.withdata.com\/blog\/wp-json\/wp\/v2\/media?parent=22479"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.withdata.com\/blog\/wp-json\/wp\/v2\/categories?post=22479"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.withdata.com\/blog\/wp-json\/wp\/v2\/tags?post=22479"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}