[XML-SIG] Fixed source for XML tutorial

Thomas Gagne tgagne@ix.netcom.com
Sun, 13 Aug 2000 21:45:39 -0400


This is a multi-part message in MIME format.
--------------FF7372391C5B4F9254B89302
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Though it was fairly easy to fix (and maybe that's part of the tutorial), the
source included doesn't work.  It calls parser.parseFile() with the an 'file'
argument but it never opened it.

--------------FF7372391C5B4F9254B89302
Content-Type: text/plain; charset=us-ascii;
 name="xmltest.py"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="xmltest.py"

#!/usr/bin/env python
from xml.sax import saxlib
from xml.sax import saxexts

class FindIssue(saxlib.HandlerBase):
	def __init__(self, title, number):
		self.search_title, self.search_number = title, number

	def startElement(self, name, attrs):
		if name != 'comic':
			return
		
		title = attrs.get('title', None)
		number = attrs.get('number', None)
		if title == self.search_title and number == self.search_number:
			print title, '#' + str(number), 'found'

if __name__ == '__main__':
	parser = saxexts.make_parser()

	dh = FindIssue('Sandman', '62')

	parser.setDocumentHandler(dh)

	fh = open('test.xml', 'r')
	parser.parseFile(fh)

	parser.close()
	fh.close()

--------------FF7372391C5B4F9254B89302--