Markup Processing Modules
xml.sax.xmlreader
Defines SAX reader interfaces and helper types such as InputSource and AttributesImpl. XMLReader represents a parser interface; choose a concrete reader via xml.sax.make_parser(). InputSource can supply a file-like stream instead of a filename. Use bounded trusted XML; parsing hostile input requires a security review and resource limits.
Formal Syntax & Structure
python syntaxpython
import xml.sax.xmlreaderReturn Value
module
Module namespace available through import; import is a statement, not a value-returning expression.
Working Example
Example Snippetpython
from io import BytesIOfrom xml.sax import make_parserfrom xml.sax.handler import ContentHandlerfrom xml.sax.xmlreader import InputSourceclass Root(ContentHandler): def startElement(self, name, attrs): print(name)source = InputSource()source.setByteStream(BytesIO(b"<root/>"))reader = make_parser()reader.setContentHandler(Root())reader.parse(source)