Differences between revisions 1 and 2
Revision 1 as of 2005-02-12 22:09:20
Size: 1177
Editor: aaron
Comment: SAX example, SAX links
Revision 2 as of 2005-02-12 22:27:14
Size: 1286
Editor: aaron
Comment: + API documentation
Deletions are marked like this. Additions are marked like this.
Line 24: Line 24:
 * [http://docs.python.org/lib/module-xml.sax.html Python Library Reference, xml.sax] -- API documentation

"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.