Differences between revisions 3 and 4
Revision 3 as of 2005-04-14 04:46:47
Size: 1352
Editor: aaron
Comment: HTMLParser is similar
Revision 4 as of 2008-07-14 09:44:20
Size: 1233
Editor: p5B2DB4B3
Comment: link not working, dont know how to comment out...
Deletions are marked like this. Additions are marked like this.
Line 27: Line 27:
 * [http://www.devchannel.org/webserviceschannel/04/05/25/1414203.shtml SAX processing in Python] -- helpful diagrams

"Sax" is an XML parser that operates element by element, line by line.

MiniDom sucks up an entire XML file, holds it in memory, and lets you work with it. Sax, on the other hand, emits events as it goes step by step through the file.

Example

   1 import xml.sax
   2 
   3 class InkscapeSvgHandler(xml.sax.ContentHandler):
   4     def startElement(self, name, attrs):
   5         if name == "svg":
   6             for (k,v) in attrs.items():
   7                 print k + " " + v
   8 
   9 parser = xml.sax.make_parser()
  10 parser.setContentHandler(InkscapeSvgHandler())
  11 parser.parse(open("svg.xml","r"))

Sax (last edited 2011-02-26 09:38:25 by StefanBehnel)

Unable to edit the page? See the FrontPage for instructions.