Outline of the program

This program uses Python's SAX parser for handling the data. For more information about Python, XML, and the SAX parser, see http://www.python.org/.

Need a more specific link

The program's outline is as follows:


Main Listing =

#!/usr/bin/python

#Import needed libraries
from xml.sax import saxlib, saxexts, saxutils
import sys, urllib, string, sre, types

{Class to handle SAX parsing functions}
{Class to handle SAX error conditions}
{Instantiate class and run parser}

The actual code to run the parser is quite simple:


Instantiate class and run parser =

#Create a SAX XML parser
parser = saxexts.make_parser()

#Instantiate our handler and error classes
ldh = LiterateDocumentHandler()
leh = LiterateErrorHandler()

#prepare parser
parser.setDocumentHandler(ldh)
parser.setErrorHandler(leh)

#parse the first argument
parser.parse(sys.argv[1])

#write out the files indicated
ldh.write_files()

Notice that we do not care about validating against a DTD, since our program is operating on processing instructions and doesn't care much about the DTD or the elements.