Parsing a xml.gz file in python
11,857
Below Code worked for me, to read and process a zipped xml file.
I have used gzip first to unzip the file and then used ElementTree.
import gzip
import xml.etree.ElementTree as ET
input = gzip.open('input-xml.gz', 'r')
tree = ET.parse(input)
root = tree.getroot()
print root.tag
print root.attrib
Author by
Admin
Updated on June 13, 2022Comments
-
Admin almost 2 years
I have an tar.gz file on my local machine called
abc.aXML.gz
, which contains many XML files. I want to find some data from these files but don't know how to parse these file usingElementtree
andgzip
.import xml.etree.ElementTree as ET import gzip document = ET.parse(gzip("abc.aXML.gz")) root = document.getroot()
-
anish about 5 yearsChanging the last line to dom = minidom.parseString(content) worked for me