Name
ContentHandler
Synopsis
class ContentHandler( )
An instance h of a subclass of
ContentHandler may override several methods, of
which the most frequently useful are the following:
-
h.characters(data) Called when textual content
datais parsed. The parser may split each range of text in the document into any number of separate callbacks toh.characters. Therefore, your implementation of methodcharactersusually buffersdata, generally by appending it to a list attribute. When your class knows from some other event that all relevant data has arrived, your class calls ''.joinon the list and processes the resulting string.-
h.endDocument( ) Called once when the document finishes.
-
h.endElement(tag) Called when the element named
tagfinishes.-
h.endElementNS(name,qname) Called when an element finishes and the parser is handling namespaces.
nameandqnameare like forstartElementNS, covered later in this chapter.-
h.startDocument( ) Called once when the document begins.
-
h.startElement(tag,attrs) Called when the element named
tagbegins.attrsis a mapping of attribute names to values, as covered in the next section.-
h.startElementNS(name,qname,attrs) Called when an element begins and the parser is handling namespaces.
nameis a pair(uri,localname), whereuriis the namespace’s URI orNone, andlocalnameis the name of the tag.qname(which stands for qualified name) is eitherNone, if the parser does not supply the namespace prefixes feature, or the string ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access