SAX is an event-driven API.
Parsing XML documents with SAX involves two parts: parser and event handler.
The parser is responsible for reading the XML document and sending events to the event handler, such as an element start with an element end event.
The event handler is responsible for responding to events and processing the passed XML data.
2. Only need part of the file, or just get specific information from the file.
3. When you want to build your own object model.
In Python, using sax to process xml first introduces the parse function in xml.sax, and the ContentHandler in xml.sax.handler.
From the beginning of the line, there are characters before the label is encountered, and the value of content is the string.
From a tag, before the next tag is encountered, there are characters, and the value of content is the string.
From a label, before the line terminator is encountered, there are characters, and the value of content is the string.
tag can be either a start tag or an end tag.
Called when the document is launched.
Called when the parser reaches the end of the document.
Invoked when the XML start tag is encountered, name is the name of the tag, and attrs is the tag's attribute value dictionary.
Called when an XML end tag is encountered.
The following method creates a new parser object and returns.