My code works for the most part. (The problems are on the html side not the python side) however I feel it could run quicker or more efficiently. Due to the size of the XML document it parses it's always going to take a little while though.The script parses the XML file and finds the names of several things, estates, symbols and ticktypes. I then create text files storing these items and for estates also use the information in an html file which will be expanded and improved later.How could I make my code a bit sleeker and more efficient?from xml.dom import minidomfrom os import remove#THIS IS THE LIVE XML FILExmldoc = minidom.parse('xxx.xml')THIS IS THE TEST XML FILExmldoc = minidom.parse('xxx.xml')#Establishing Lists of Items for use in defined Functionssymlist = xmldoc.getElementsByTagName('Symbol')EstateList = xmldoc.getElementsByTagName('Estate')ticklist = xmldoc.getElementsByTagName('Ticktype')tickset = set(s.firstChild.data for s in ticklist)#ESTATESdef ESTATES():    with open('estate.txt', 'w') as f:        f.write(There are currently %d Data Estates \n \n % len(EstateList))        for s in EstateList:             f.write(s.attributes['EstateName'].value + \n)#TICK TYPESdef TICKS():    with open('ticktypes.txt', 'w') as e:        e.write(There are currently %d unique Tick Types \n \n % len(tickset))        for s in tickset:            e.write(s + \n)#SYMBOLSdef SYMS():    with open('symbollist.txt', 'w') as g:        g.write(There are currently %d unique Symbols \n \n % len(symlist))        for s in symlist:            g.write(s.attributes['SymbolName'].value + \n) def uniquelines(lineslist):     unique = {}     result = []    for item in lineslist:        if item.strip() in unique: continue        unique[item.strip()] = 1        result.append(item)    return resultwith open('Z:\Joe\\temp.txt', 'w') as z:    for element in EstateList:        EstateStr = element.getAttribute('EstateName')        asset = EstateStr.split('.', 3)[2]        z.write(asset + \n)with open('Z:\Joe\\temp.txt','r+') as f:    filelines = f.readlines()with open(Z:\Joe\\assets.txt, w) as output:output.write(There are currently %d unique Assets \n \n %len(uniquelines(filelines)))output.writelines(uniquelines(filelines))remove('Z:\Joe\\temp.txt')ESTATES()TICKS()SYMS()print There are currently %d Symbols, %d Unique Tick Types, %d Data Estates and %d unique assets % (len(symlist), len(tickset), len(EstateList), len(uniquelines(filelines)))print Compiling data into html pageswith open(C:\code\jsdd\Dropdown\home.html, w) as f:    f.write('<!DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Transitional//EN     http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd> \n')    f.write('<html xmlns=http://www.w3.org/1999/xhtml> \n')    f.write('<head> \n')    f.write('<meta http-equiv=Content-Type content=text/html; charset=iso-8859-1 /> \n')    f.write('<title>JavaScript Dropdown</title> \n')    f.write('<link rel=stylesheet href=design.css type=text/css /> \n')    f.write('<script type=text/javascript src=drop.js></script> \n')    f.write('</head> \n')    f.write('<body> \n')    f.write('\n')    f.write('<dl class=dropdown> \n')    f.write('\t <dt id=one-ddheader onmouseover=ddMenu(\'one\',1) onmouseout=ddMenu(\'one\',-1)>Data Estates</dt> \n')    f.write('\t <dd id=one-ddcontent onmouseover=cancelHide(\'one\') onmouseout=ddMenu(\'one\',-1)> \n')    f.write('\t \t <ul> \n')    for estate in EstateList:        f.write('\t \t  <li><a href=# class=seperator>' + (estate.attributes['EstateName'].value) + '</a></li> \n')    f.write('\t \t </ul> \n')    f.write('\t </dd> \n')    f.write('\t </dl> \n')    f.write('</dl> \n')    f.write('<div style=clear:both /> \n')    f.write('</body> \n')    f.write('</html> \n')I have changed some file names and hidden some as this is for work so  don't want to risk breaching confidentiality.
Parsing XML to send data into several files
python;html;parsing;xml;file system
Not having any example xml file, I cannot test the code provided, but I can see that it relies on xml.dom.minidom.getElementsByTagName. My suggestion here is to give a try xml.sax and see if it's more efficient because:There's no need to keep in memory the whole xml documentYou can get results about the three things you're interested in in a single passSome comments regarding the style of the code provided:Use # for comments. Note that triple quotes is just a way to create a string object and drop it immediately unless is assigned to a variable.Function names should be in lower case lettersAvoid short names for variables like e and g (I don't have a problem with f though if it's a file).Use a main function in the script to make clearer what is the intended execution pathWrite docstrings (PEP257)Use a template engine to generate the HTML document (I like jinja, but there are others like mako or cheetah).