Markup Processing Modules
xml.sax
Provides event-driven XML parsing through SAX2 interfaces. Register handlers for callbacks rather than building an entire tree. Text callbacks may arrive in chunks, so accumulate them when reconstructing text. Use bounded trusted XML; parsing hostile input requires a security review and resource limits.
Formal Syntax & Structure
python syntaxpython
import xml.saxReturn Value
module
Module namespace available through import; import is a statement, not a value-returning expression.
Working Example
Example Snippetpython
from xml.sax import parseStringfrom xml.sax.handler import ContentHandlerclass Tags(ContentHandler): def startElement(self, name, attrs): print(name)parseString("<root><item/></root>", Tags())