{"id":6857,"date":"2020-12-25T20:05:25","date_gmt":"2020-12-25T14:35:25","guid":{"rendered":"http:\/\/www.pythonpool.com\/?p=6857"},"modified":"2021-06-14T15:12:05","modified_gmt":"2021-06-14T09:42:05","slug":"python-xml-to-csv","status":"publish","type":"post","link":"https:\/\/www.pythonpool.com\/python-xml-to-csv\/","title":{"rendered":"XML to CSV Conversion Using Python"},"content":{"rendered":"\n<p>Hello coders!! In this article we will learn how to convert an xml file into a csv file in python. So without much ado lets directly dive into the topic.<\/p>\n\n\n\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_74 counter-hierarchy ez-toc-counter ez-toc-transparent ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #990303;color:#990303\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #990303;color:#990303\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 eztoc-toggle-hide-by-default' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/www.pythonpool.com\/python-xml-to-csv\/#What_is_XML\" >What is XML?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/www.pythonpool.com\/python-xml-to-csv\/#What_is_CSV\" >What is CSV?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/www.pythonpool.com\/python-xml-to-csv\/#Converting_an_xml_to_csv_file\" >Converting an xml to csv file:<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/www.pythonpool.com\/python-xml-to-csv\/#Python_Program_to_Convert_XML_to_CSV\" >Python Program to Convert XML to CSV<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/www.pythonpool.com\/python-xml-to-csv\/#The_output_of_above_code\" >The output of above code:<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/www.pythonpool.com\/python-xml-to-csv\/#Explanation_of_code_for_Converting_Python_XML_to_CSV\" >Explanation of code for Converting Python XML to CSV:<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/www.pythonpool.com\/python-xml-to-csv\/#Must_Read\" >Must Read<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/www.pythonpool.com\/python-xml-to-csv\/#Conclusion_Python_XML_to_CSV\" >Conclusion: Python XML to CSV<\/a><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\" id=\"h-what-is-xml\"><span class=\"ez-toc-section\" id=\"What_is_XML\"><\/span>What is XML?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p><a href=\"https:\/\/en.wikipedia.org\/wiki\/XML\" target=\"_blank\" rel=\"noreferrer noopener\">XML<\/a> stands for Extensible Markup Language. It is a hierarchical data used to track data (small to medium amount) without using SQL as the backbone. It is designed to store the data and also transfer it.  As a result, the XML format data is not very user-friendly, which gives rise to the need to change the format into a more easy and user-friendly one, like CSV.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-what-is-csv\"><span class=\"ez-toc-section\" id=\"What_is_CSV\"><\/span>What is CSV?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p><a href=\"https:\/\/en.wikipedia.org\/wiki\/Comma-separated_values\" target=\"_blank\" rel=\"noreferrer noopener\">CSV<\/a> stands for Comma Separated Values. As the name suggests, the data is separated using comma as delimiters. It is the most used format for import and export format of spreadsheets and databases.&nbsp;<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-converting-an-xml-to-csv-file\"><span class=\"ez-toc-section\" id=\"Converting_an_xml_to_csv_file\"><\/span>Converting an xml to csv file:<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p><strong><em>Consider the following XML file :<\/em><\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;State&gt;\n&lt;Resident Id=\"100\"&gt;\n&lt;Name&gt;John Doe&lt;\/Name&gt;\n\t&lt;Phone&gt;1234567891&lt;\/Phone&gt;\n\t&lt;Email&gt;Johndoe@example.com&lt;\/Email&gt;\n\t\n&lt;\/Resident&gt;\n&lt;Resident Id=\"101\"&gt;\n\t&lt;Name&gt;Jane Doe&lt;\/Name&gt;\n\t&lt;Phone&gt;1234567891&lt;\/Phone&gt;\n\t&lt;Email&gt;Janedoe@example.com&lt;\/Email&gt;\n\t\n&lt;\/Resident&gt;\n.\n.\n.\n.\n&lt;\/State&gt;<\/code><\/pre>\n\n\n\n<p>In this xml file we are storing the details of the residents of a state. The information stored are:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Id<\/li><li>Name<\/li><li>Phone Number<\/li><li>Email Address<\/li><\/ul>\n\n\n\n<p>Here, we have taken only two details as an example:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Id: 100<\/li><li>Name: John Doe<\/li><li>Phone: 1234567891<\/li><li>Email: Johndoe@example.com<\/li><\/ul>\n\n\n\n<ul class=\"wp-block-list\" id=\"block-5ce6df03-5489-4ef0-a7ed-70b01b3d7054\"><li>Id: 101<\/li><li>Name: Jane Doe<\/li><li>Phone: 1234567891<\/li><li>Email: Janedoe@example.com<\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-python-program-to-convert-xml-to-csv\"><span class=\"ez-toc-section\" id=\"Python_Program_to_Convert_XML_to_CSV\"><\/span>Python Program to Convert XML to CSV<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>From the above example, we can understand that if the number of residents increases, it becomes difficult to read and understand the data. This is the reason why we will now convert this XML format file into a CSV format file.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\nimport xml.etree.ElementTree as ET\nimport csv\n\ntree = ET.parse(&quot;sample.xml&quot;)\nroot = tree.getroot()\n\nResident_data = open('ResidentData.csv', 'w')\n\ncsvwriter = csv.writer(Resident_data)\nresident_head = &#x5B;]\n\ncount = 0\nfor member in root.findall('Resident'):\n\tresident = &#x5B;]\n\taddress_list = &#x5B;]\n\tif count == 0:\n\t\tname = member.find('Name').tag\n\t\tresident_head.append(name)\n\t\tPhone = member.find('Phone').tag\n\t\tresident_head.append(Phone)\n\t\tEmail = member.find('Email').tag\n\t\tresident_head.append(Email)\n\t\t\n\t\tcsvwriter.writerow(resident_head)\n\t\tcount = count + 1\n\n\tname = member.find('Name').text\n\tresident.append(name)\n\tPhone = member.find('Phone').text\n\tresident.append(Phone)\n\tEmail = member.find('Email').text\n\tresident.append(Email)\n\t\n\tcsvwriter.writerow(resident)\n\n\nResident_data.close()\n<\/pre><\/div>\n\n\n<h2 class=\"wp-block-heading\" id=\"h-the-output-of-above-code\"><span class=\"ez-toc-section\" id=\"The_output_of_above_code\"><\/span>The output of above code:<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<figure class=\"wp-block-table aligncenter is-style-stripes\"><table><tbody><tr><th class=\"has-text-align-center\" data-align=\"center\">Name<\/th><th class=\"has-text-align-center\" data-align=\"center\">PhoneNumber<\/th><th class=\"has-text-align-center\" data-align=\"center\">EmailAddress<\/th><\/tr><tr><td class=\"has-text-align-center\" data-align=\"center\">John Doe<\/td><td class=\"has-text-align-center\" data-align=\"center\">1234567891<\/td><td class=\"has-text-align-center\" data-align=\"center\">Johndoe@example.com<\/td><\/tr><tr><td class=\"has-text-align-center\" data-align=\"center\">Jane Doe<\/td><td class=\"has-text-align-center\" data-align=\"center\">1234567891<\/td><td class=\"has-text-align-center\" data-align=\"center\">Janedoe@example.com<\/td><\/tr><\/tbody><\/table><figcaption><strong><em>Output<\/em><\/strong><\/figcaption><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-explanation-of-code-for-converting-python-xml-to-csv\"><span class=\"ez-toc-section\" id=\"Explanation_of_code_for_Converting_Python_XML_to_CSV\"><\/span>Explanation of code for Converting Python XML to CSV:<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>At first,two modules are imported:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>xml.etree.ElementTree:<\/strong> to create a simple API for parsing and implementing XML data<\/li><li><strong>CSV: <\/strong>to access the data in CSV format<\/li><\/ul>\n\n\n\n<p>The next two functions is used to parse through the xml file:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><strong>parse()<\/strong>: to parses= the \u2018Sample.xml\u2019 file<\/li><li><strong>getroot()<\/strong>:  returns the root element of \u2018Sample.xml\u2019<\/li><\/ul>\n\n\n\n<div class=\"wp-block-group\"><div class=\"wp-block-group__inner-container is-layout-flow wp-block-group-is-layout-flow\">\n<p>Next, we have opened a file <em>ResidentData.csv <\/em>dor writing <\/p>\n\n\n\n<p>We then created a CSV writer object <em>Resident_data<\/em><\/p>\n\n\n\n<p>Then We <a href=\"http:\/\/www.pythonpool.com\/python-iterate-through-list\/\" target=\"_blank\" rel=\"noreferrer noopener\">iterated<\/a> through the XML file, starting from the root element<\/p>\n\n\n\n<p>We directly added the details of the root element to our CSV format file and incremented the counter value<\/p>\n\n\n\n<p>For other entries we appended the details to the CSV format file without changing the counter value<\/p>\n\n\n\n<p>After each entry we have also closed the particular row<\/p>\n\n\n\n<p>When all the data is entered, we close the CSV format file as well.<\/p>\n<\/div><\/div>\n\n\n\n<h2 class=\"has-vivid-red-color has-text-color wp-block-heading\" id=\"h-must-read\"><span class=\"ez-toc-section\" id=\"Must_Read\"><\/span>Must Read<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"http:\/\/www.pythonpool.com\/pandas-to-csv\/\" rel=\"noreferrer noopener\" target=\"_blank\">Using Pandas to CSV() with Perfection<\/a><\/li><li><a href=\"http:\/\/www.pythonpool.com\/python-int-to-binary\/\" rel=\"noreferrer noopener\" target=\"_blank\">Python int to Binary | Integer to Binary Conversion<\/a><\/li><li><a href=\"http:\/\/www.pythonpool.com\/python-delete-file\/\" rel=\"noreferrer noopener\" target=\"_blank\">[Best] Ways to Delete a File in Python<\/a><\/li><li><a href=\"http:\/\/www.pythonpool.com\/python-text-to-pdf\/\" rel=\"noreferrer noopener\" target=\"_blank\">Convert Text File to PDF Using Python | FPDF<\/a><\/li><\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-conclusion-python-xml-to-csv\"><span class=\"ez-toc-section\" id=\"Conclusion_Python_XML_to_CSV\"><\/span>Conclusion: Python XML to CSV<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>In this article, we learned about the conversion of Python XML and CSV format. We saw examples for each and further learned a python implementation of converting an XML file to a CSV file in Python.<\/p>\n\n\n\n<p>However, if you have any doubts or questions, do let me know in the comment section below. I will try to help you as soon as possible.<\/p>\n\n\n\n<p><strong><em>Happy Pythoning!<\/em><\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hello coders!! In this article we will learn how to convert an xml file into a csv file in python. So without much ado lets &#8230; <\/p>\n<p class=\"read-more-container\"><a title=\"XML to CSV Conversion Using Python\" class=\"read-more button\" href=\"https:\/\/www.pythonpool.com\/python-xml-to-csv\/#more-6857\" aria-label=\"More on XML to CSV Conversion Using Python\">Read more<\/a><\/p>\n","protected":false},"author":12,"featured_media":6939,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_mi_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[296,135,15],"tags":[3008,3010,3009,3011,3005,3007,3006],"class_list":["post-6857","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-how-to","category-learning","category-tutorials","tag-convert-all-elements-in-xml-to-csv-in-python","tag-convert-xml-to-csv-python","tag-convert-xml-to-csv-python-utf-8","tag-converting-xml-to-csv-using-xml-utils-python-script","tag-python-convert-xml-to-csv","tag-python-parse-xml-file-to-csv","tag-write-xml-data-to-csv-file-python","infinite-scroll-item"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v20.1 (Yoast SEO v25.0) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>XML to CSV Conversion Using Python - Python Pool<\/title>\n<meta name=\"description\" content=\"Python XML to CSV conversion is needed as data in XML format is hierarchical and not user friendly. CSV format is mostly used for import\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.pythonpool.com\/python-xml-to-csv\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"XML to CSV Conversion Using Python\" \/>\n<meta property=\"og:description\" content=\"Hello coders!! In this article we will learn how to convert an xml file into a csv file in python. So without much ado lets directly dive into the topic.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.pythonpool.com\/python-xml-to-csv\/\" \/>\n<meta property=\"og:site_name\" content=\"Python Pool\" \/>\n<meta property=\"article:published_time\" content=\"2020-12-25T14:35:25+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-06-14T09:42:05+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/12\/Theatre-Actor-Portfolio-Website-49.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1350\" \/>\n\t<meta property=\"og:image:height\" content=\"650\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Prachee Sao\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@pythonpool\" \/>\n<meta name=\"twitter:site\" content=\"@pythonpool\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Prachee Sao\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.pythonpool.com\/python-xml-to-csv\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.pythonpool.com\/python-xml-to-csv\/\"},\"author\":{\"name\":\"Prachee Sao\",\"@id\":\"https:\/\/www.pythonpool.com\/#\/schema\/person\/b91d749826b21e606d55cda77d51ef47\"},\"headline\":\"XML to CSV Conversion Using Python\",\"datePublished\":\"2020-12-25T14:35:25+00:00\",\"dateModified\":\"2021-06-14T09:42:05+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.pythonpool.com\/python-xml-to-csv\/\"},\"wordCount\":530,\"commentCount\":9,\"publisher\":{\"@id\":\"https:\/\/www.pythonpool.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/www.pythonpool.com\/python-xml-to-csv\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/12\/Theatre-Actor-Portfolio-Website-49.png\",\"keywords\":[\"convert all elements in xml to csv in python\",\"convert xml to csv python\",\"convert xml to csv python utf-8\",\"converting xml to csv using xml utils python script\",\"python convert xml to csv\",\"python parse xml file to csv\",\"write xml data to csv file python\"],\"articleSection\":[\"How to\",\"Learning\",\"Tutorials\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/www.pythonpool.com\/python-xml-to-csv\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.pythonpool.com\/python-xml-to-csv\/\",\"url\":\"https:\/\/www.pythonpool.com\/python-xml-to-csv\/\",\"name\":\"XML to CSV Conversion Using Python - Python Pool\",\"isPartOf\":{\"@id\":\"https:\/\/www.pythonpool.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.pythonpool.com\/python-xml-to-csv\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.pythonpool.com\/python-xml-to-csv\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/12\/Theatre-Actor-Portfolio-Website-49.png\",\"datePublished\":\"2020-12-25T14:35:25+00:00\",\"dateModified\":\"2021-06-14T09:42:05+00:00\",\"description\":\"Python XML to CSV conversion is needed as data in XML format is hierarchical and not user friendly. CSV format is mostly used for import\",\"breadcrumb\":{\"@id\":\"https:\/\/www.pythonpool.com\/python-xml-to-csv\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.pythonpool.com\/python-xml-to-csv\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.pythonpool.com\/python-xml-to-csv\/#primaryimage\",\"url\":\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/12\/Theatre-Actor-Portfolio-Website-49.png\",\"contentUrl\":\"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/12\/Theatre-Actor-Portfolio-Website-49.png\",\"width\":1350,\"height\":650,\"caption\":\"python xml to csv\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.pythonpool.com\/python-xml-to-csv\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.pythonpool.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"XML to CSV Conversion Using Python\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.pythonpool.com\/#website\",\"url\":\"https:\/\/www.pythonpool.com\/\",\"name\":\"Python Pool\",\"description\":\"Your One-Stop Python Learning Destination\",\"publisher\":{\"@id\":\"https:\/\/www.pythonpool.com\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.pythonpool.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.pythonpool.com\/#organization\",\"name\":\"Python Pool\",\"url\":\"https:\/\/www.pythonpool.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.pythonpool.com\/#\/schema\/logo\/image\/\",\"url\":\"http:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/08\/aa.png\",\"contentUrl\":\"http:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/08\/aa.png\",\"width\":452,\"height\":185,\"caption\":\"Python Pool\"},\"image\":{\"@id\":\"https:\/\/www.pythonpool.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/x.com\/pythonpool\",\"https:\/\/www.youtube.com\/c\/pythonpool\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.pythonpool.com\/#\/schema\/person\/b91d749826b21e606d55cda77d51ef47\",\"name\":\"Prachee Sao\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.pythonpool.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/d018c3758049ab2511d0772ac1f73c338aaa8c921577f39e0f1e5716fc7efcb4?s=96&d=wavatar&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/d018c3758049ab2511d0772ac1f73c338aaa8c921577f39e0f1e5716fc7efcb4?s=96&d=wavatar&r=g\",\"caption\":\"Prachee Sao\"}}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"XML to CSV Conversion Using Python - Python Pool","description":"Python XML to CSV conversion is needed as data in XML format is hierarchical and not user friendly. CSV format is mostly used for import","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.pythonpool.com\/python-xml-to-csv\/","og_locale":"en_US","og_type":"article","og_title":"XML to CSV Conversion Using Python","og_description":"Hello coders!! In this article we will learn how to convert an xml file into a csv file in python. So without much ado lets directly dive into the topic.","og_url":"https:\/\/www.pythonpool.com\/python-xml-to-csv\/","og_site_name":"Python Pool","article_published_time":"2020-12-25T14:35:25+00:00","article_modified_time":"2021-06-14T09:42:05+00:00","og_image":[{"width":1350,"height":650,"url":"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/12\/Theatre-Actor-Portfolio-Website-49.png","type":"image\/png"}],"author":"Prachee Sao","twitter_card":"summary_large_image","twitter_creator":"@pythonpool","twitter_site":"@pythonpool","twitter_misc":{"Written by":"Prachee Sao","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.pythonpool.com\/python-xml-to-csv\/#article","isPartOf":{"@id":"https:\/\/www.pythonpool.com\/python-xml-to-csv\/"},"author":{"name":"Prachee Sao","@id":"https:\/\/www.pythonpool.com\/#\/schema\/person\/b91d749826b21e606d55cda77d51ef47"},"headline":"XML to CSV Conversion Using Python","datePublished":"2020-12-25T14:35:25+00:00","dateModified":"2021-06-14T09:42:05+00:00","mainEntityOfPage":{"@id":"https:\/\/www.pythonpool.com\/python-xml-to-csv\/"},"wordCount":530,"commentCount":9,"publisher":{"@id":"https:\/\/www.pythonpool.com\/#organization"},"image":{"@id":"https:\/\/www.pythonpool.com\/python-xml-to-csv\/#primaryimage"},"thumbnailUrl":"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/12\/Theatre-Actor-Portfolio-Website-49.png","keywords":["convert all elements in xml to csv in python","convert xml to csv python","convert xml to csv python utf-8","converting xml to csv using xml utils python script","python convert xml to csv","python parse xml file to csv","write xml data to csv file python"],"articleSection":["How to","Learning","Tutorials"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.pythonpool.com\/python-xml-to-csv\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.pythonpool.com\/python-xml-to-csv\/","url":"https:\/\/www.pythonpool.com\/python-xml-to-csv\/","name":"XML to CSV Conversion Using Python - Python Pool","isPartOf":{"@id":"https:\/\/www.pythonpool.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.pythonpool.com\/python-xml-to-csv\/#primaryimage"},"image":{"@id":"https:\/\/www.pythonpool.com\/python-xml-to-csv\/#primaryimage"},"thumbnailUrl":"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/12\/Theatre-Actor-Portfolio-Website-49.png","datePublished":"2020-12-25T14:35:25+00:00","dateModified":"2021-06-14T09:42:05+00:00","description":"Python XML to CSV conversion is needed as data in XML format is hierarchical and not user friendly. CSV format is mostly used for import","breadcrumb":{"@id":"https:\/\/www.pythonpool.com\/python-xml-to-csv\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.pythonpool.com\/python-xml-to-csv\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.pythonpool.com\/python-xml-to-csv\/#primaryimage","url":"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/12\/Theatre-Actor-Portfolio-Website-49.png","contentUrl":"https:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/12\/Theatre-Actor-Portfolio-Website-49.png","width":1350,"height":650,"caption":"python xml to csv"},{"@type":"BreadcrumbList","@id":"https:\/\/www.pythonpool.com\/python-xml-to-csv\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.pythonpool.com\/"},{"@type":"ListItem","position":2,"name":"XML to CSV Conversion Using Python"}]},{"@type":"WebSite","@id":"https:\/\/www.pythonpool.com\/#website","url":"https:\/\/www.pythonpool.com\/","name":"Python Pool","description":"Your One-Stop Python Learning Destination","publisher":{"@id":"https:\/\/www.pythonpool.com\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.pythonpool.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.pythonpool.com\/#organization","name":"Python Pool","url":"https:\/\/www.pythonpool.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.pythonpool.com\/#\/schema\/logo\/image\/","url":"http:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/08\/aa.png","contentUrl":"http:\/\/www.pythonpool.com\/wp-content\/uploads\/2020\/08\/aa.png","width":452,"height":185,"caption":"Python Pool"},"image":{"@id":"https:\/\/www.pythonpool.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/x.com\/pythonpool","https:\/\/www.youtube.com\/c\/pythonpool"]},{"@type":"Person","@id":"https:\/\/www.pythonpool.com\/#\/schema\/person\/b91d749826b21e606d55cda77d51ef47","name":"Prachee Sao","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.pythonpool.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/d018c3758049ab2511d0772ac1f73c338aaa8c921577f39e0f1e5716fc7efcb4?s=96&d=wavatar&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/d018c3758049ab2511d0772ac1f73c338aaa8c921577f39e0f1e5716fc7efcb4?s=96&d=wavatar&r=g","caption":"Prachee Sao"}}]}},"_links":{"self":[{"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/posts\/6857","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/users\/12"}],"replies":[{"embeddable":true,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/comments?post=6857"}],"version-history":[{"count":8,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/posts\/6857\/revisions"}],"predecessor-version":[{"id":13551,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/posts\/6857\/revisions\/13551"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/media\/6939"}],"wp:attachment":[{"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/media?parent=6857"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/categories?post=6857"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.pythonpool.com\/wp-json\/wp\/v2\/tags?post=6857"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}