-
-
Save pbteja1998/c472d63337d8aa9bb0a059548b255d98 to your computer and use it in GitHub Desktop.
As basic as a python SAX parser can get.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys, string | |
from xml.sax import saxutils, handler, make_parser | |
class ContentGenerator(handler.ContentHandler): | |
def __init__(self, out = sys.stdout): | |
handler.ContentHandler.__init__(self) | |
def startDocument(self): | |
print 'start' | |
def startElement(self, name, attrs): | |
print 'start', name | |
for attr_name, value in attrs.items(): | |
print attr_name, value | |
def endElement(self, name): | |
print 'end', name | |
def characters(self, content): | |
print content | |
def ignorableWhitespace(self, content): | |
print 'whitespace', '"', content, '"' | |
def processingInstruction(self, target, data): | |
print 'processing instruction', target, data | |
if __name__ == '__main__': | |
parser = make_parser() | |
parser.setContentHandler(ContentGenerator()) | |
parser.parse(sys.argv[1]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment