XUL Parser in Python/source

Source code for the XUL Parser in Python.

import sys, glob, xmllib
import os, re
el_list = {}
w = open('res.html', 'w')

# Unfortunately, I had to put this hack in here to suppress the printing out of the resolved namespace: 
# "xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul window", etc.

def strip(snip):
	t = re.sub('http://.*?\s', '', snip)
	return t
		
class XULParser(xmllib.XMLParser):
	def unknown_starttag(self, t, a):
		name = strip(t)
		if name not in el_list: el_list[name] = {}
		for attr,val in a.items():
			el_list[name][strip(attr)] = strip(val)
			
	def syntax_error(self, message):
		pass

p = XULParser()

cmd = 'dir /s /b *.xul'
CHROME_DIR = 'C:\Program Files\Netscape\Netscape 6\chrome' 
os.chdir(CHROME_DIR)
files = os.popen(cmd).readlines()
for file in files:
	file = file.strip()
	print '** ' + file + ' **'
	data = open(file).read()
	p.feed(data)

w.write('<html><h3>Periodic Table of XUL Elements</h3>')
w.write('<table><style>.head {font-weight: bold; background-color: lightgrey;}</style>')
  
elements = el_list.keys()
elements.sort()
for item in elements:
	w.write('<tr><td class="head">' + item + '</td></tr>\n')
	for a in el_list[item]:
		w.write('<tr><td class="at">' + a + '</td>')
	
w.write('</table></html>\n')
w.close()

Document Tags and Contributors

Last updated by: ethertank,