See the results below:Īs you can see the xml.tree module is at least twice faster than the xmltodict module, and much faster than the untangle module. To compare these three modules, I have created an XML file with 600 employees and get the running time in milliseconds for each module. Since the approaches to convert xml and csv are quite similar, which one should you choose? Choosing the fastest is always a good idea. Untangle is a third-party module as well, therefore you will need to install it separetaly usign pip as follows:Ĭsvfile = open("data3.csv",'w',encoding='utf-8')Ĭsv_line = Similarly to the xmltodict, the untangle module parses an XMl document and make the data easily accessible. Lastly you can convert XML to CSV using a Python module called untangle. The output of the above code snippet is a file called data2.csv containing the employees information.Īnother useful thing to know about the xmltodict module is that it allows you to convert a dictionary to xml. find(""): This method will find the first child element with the a given tag.Ĭsvfile = open("data2.csv",'w',encoding='utf-8')Ĭsvfile_writer.writerow()įor employee in xml:Ĭsv_line =, employee,employee] findall(""): it will find all elements with a given tag that are direct children of the current element.
0 Comments
Leave a Reply. |