Skip to content
Advertisement

Multiple xml files to csv using python

I am trying to extract specific tags from XML and converting to CSV file. i was able to this for single XML file which is extracting all the identifier tag in the file. Here my question is 1) how to extract from multiple XML files to single CSV file and 2) in the given XML file the required tag is mentioned more than once i would like to know how to extract the first identifier tag from each list of record tag.

Am using python3.7

Required ans is:

JavaScript

Note: am not a programmer!! appreciate your kind help.

JavaScript

xml file example:

JavaScript

Advertisement

Answer

This script will go through every XML in the directory (*.xml) and extract the first <identifier> under the <record> tag:

JavaScript

Prints (for example):

JavaScript

And saves data.csv (screenshot from LibreOffice):

enter image description here

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement