Fred Drake | 295da24 | 1998-08-10 19:42:37 +0000 | [diff] [blame] | 1 | \section{\module{xmllib} --- |
| 2 | A parser for XML documents.} |
Guido van Rossum | a10768a | 1997-11-18 15:11:22 +0000 | [diff] [blame] | 3 | % Author: Sjoerd Mullender |
Fred Drake | b91e934 | 1998-07-23 17:59:49 +0000 | [diff] [blame] | 4 | \declaremodule{standard}{xmllib} |
| 5 | |
| 6 | \modulesynopsis{A parser for XML documents.} |
| 7 | |
Guido van Rossum | a10768a | 1997-11-18 15:11:22 +0000 | [diff] [blame] | 8 | \index{XML} |
| 9 | |
Fred Drake | 3b5da76 | 1998-03-12 15:33:05 +0000 | [diff] [blame] | 10 | This module defines a class \class{XMLParser} which serves as the basis |
Guido van Rossum | a10768a | 1997-11-18 15:11:22 +0000 | [diff] [blame] | 11 | for parsing text files formatted in XML (eXtended Markup Language). |
| 12 | |
Fred Drake | 3b5da76 | 1998-03-12 15:33:05 +0000 | [diff] [blame] | 13 | \begin{classdesc}{XMLParser}{} |
| 14 | The \class{XMLParser} class must be instantiated without arguments. |
| 15 | \end{classdesc} |
| 16 | |
| 17 | This class provides the following interface methods: |
Guido van Rossum | a10768a | 1997-11-18 15:11:22 +0000 | [diff] [blame] | 18 | |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 19 | \begin{methoddesc}{reset}{} |
Guido van Rossum | a10768a | 1997-11-18 15:11:22 +0000 | [diff] [blame] | 20 | Reset the instance. Loses all unprocessed data. This is called |
| 21 | implicitly at the instantiation time. |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 22 | \end{methoddesc} |
Guido van Rossum | a10768a | 1997-11-18 15:11:22 +0000 | [diff] [blame] | 23 | |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 24 | \begin{methoddesc}{setnomoretags}{} |
Guido van Rossum | a10768a | 1997-11-18 15:11:22 +0000 | [diff] [blame] | 25 | Stop processing tags. Treat all following input as literal input |
| 26 | (CDATA). |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 27 | \end{methoddesc} |
Guido van Rossum | a10768a | 1997-11-18 15:11:22 +0000 | [diff] [blame] | 28 | |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 29 | \begin{methoddesc}{setliteral}{} |
Guido van Rossum | f484a33 | 1998-12-07 21:59:56 +0000 | [diff] [blame] | 30 | Enter literal mode (CDATA mode). This mode is automatically exited |
| 31 | when the close tag matching the last unclosed open tag is encountered. |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 32 | \end{methoddesc} |
Guido van Rossum | a10768a | 1997-11-18 15:11:22 +0000 | [diff] [blame] | 33 | |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 34 | \begin{methoddesc}{feed}{data} |
Guido van Rossum | a10768a | 1997-11-18 15:11:22 +0000 | [diff] [blame] | 35 | Feed some text to the parser. It is processed insofar as it consists |
| 36 | of complete elements; incomplete data is buffered until more data is |
Fred Drake | 3b5da76 | 1998-03-12 15:33:05 +0000 | [diff] [blame] | 37 | fed or \method{close()} is called. |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 38 | \end{methoddesc} |
Guido van Rossum | a10768a | 1997-11-18 15:11:22 +0000 | [diff] [blame] | 39 | |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 40 | \begin{methoddesc}{close}{} |
Guido van Rossum | a10768a | 1997-11-18 15:11:22 +0000 | [diff] [blame] | 41 | Force processing of all buffered data as if it were followed by an |
| 42 | end-of-file mark. This method may be redefined by a derived class to |
| 43 | define additional processing at the end of the input, but the |
Fred Drake | 3b5da76 | 1998-03-12 15:33:05 +0000 | [diff] [blame] | 44 | redefined version should always call \method{close()}. |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 45 | \end{methoddesc} |
Guido van Rossum | a10768a | 1997-11-18 15:11:22 +0000 | [diff] [blame] | 46 | |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 47 | \begin{methoddesc}{translate_references}{data} |
Fred Drake | 3b5da76 | 1998-03-12 15:33:05 +0000 | [diff] [blame] | 48 | Translate all entity and character references in \var{data} and |
Guido van Rossum | 02505e4 | 1998-01-29 14:55:24 +0000 | [diff] [blame] | 49 | returns the translated string. |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 50 | \end{methoddesc} |
Guido van Rossum | 02505e4 | 1998-01-29 14:55:24 +0000 | [diff] [blame] | 51 | |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 52 | \begin{methoddesc}{handle_xml}{encoding, standalone} |
| 53 | This method is called when the \samp{<?xml ...?>} tag is processed. |
Guido van Rossum | 02505e4 | 1998-01-29 14:55:24 +0000 | [diff] [blame] | 54 | The arguments are the values of the encoding and standalone attributes |
| 55 | in the tag. Both encoding and standalone are optional. The values |
Fred Drake | 3b5da76 | 1998-03-12 15:33:05 +0000 | [diff] [blame] | 56 | passed to \method{handle_xml()} default to \code{None} and the string |
Guido van Rossum | 02505e4 | 1998-01-29 14:55:24 +0000 | [diff] [blame] | 57 | \code{'no'} respectively. |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 58 | \end{methoddesc} |
Guido van Rossum | 02505e4 | 1998-01-29 14:55:24 +0000 | [diff] [blame] | 59 | |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 60 | \begin{methoddesc}{handle_doctype}{tag, data} |
| 61 | This method is called when the \samp{<!DOCTYPE...>} tag is processed. |
Guido van Rossum | 02505e4 | 1998-01-29 14:55:24 +0000 | [diff] [blame] | 62 | The arguments are the name of the root element and the uninterpreted |
| 63 | contents of the tag, starting after the white space after the name of |
| 64 | the root element. |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 65 | \end{methoddesc} |
Guido van Rossum | 02505e4 | 1998-01-29 14:55:24 +0000 | [diff] [blame] | 66 | |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 67 | \begin{methoddesc}{handle_starttag}{tag, method, attributes} |
Guido van Rossum | a10768a | 1997-11-18 15:11:22 +0000 | [diff] [blame] | 68 | This method is called to handle start tags for which a |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 69 | \method{start_\var{tag}()} method has been defined. The \var{tag} |
| 70 | argument is the name of the tag, and the \var{method} argument is the |
Guido van Rossum | a10768a | 1997-11-18 15:11:22 +0000 | [diff] [blame] | 71 | bound method which should be used to support semantic interpretation |
| 72 | of the start tag. The \var{attributes} argument is a dictionary of |
| 73 | attributes, the key being the \var{name} and the value being the |
| 74 | \var{value} of the attribute found inside the tag's \code{<>} brackets. |
Guido van Rossum | 02505e4 | 1998-01-29 14:55:24 +0000 | [diff] [blame] | 75 | Character and entity references in the \var{value} have |
Guido van Rossum | a10768a | 1997-11-18 15:11:22 +0000 | [diff] [blame] | 76 | been interpreted. For instance, for the tag |
| 77 | \code{<A HREF="http://www.cwi.nl/">}, this method would be called as |
Fred Drake | b0744c5 | 1997-12-29 19:59:38 +0000 | [diff] [blame] | 78 | \code{handle_starttag('A', self.start_A, \{'HREF': 'http://www.cwi.nl/'\})}. |
Fred Drake | 3b5da76 | 1998-03-12 15:33:05 +0000 | [diff] [blame] | 79 | The base implementation simply calls \var{method} with \var{attributes} |
Guido van Rossum | a10768a | 1997-11-18 15:11:22 +0000 | [diff] [blame] | 80 | as the only argument. |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 81 | \end{methoddesc} |
Guido van Rossum | a10768a | 1997-11-18 15:11:22 +0000 | [diff] [blame] | 82 | |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 83 | \begin{methoddesc}{handle_endtag}{tag, method} |
Guido van Rossum | a10768a | 1997-11-18 15:11:22 +0000 | [diff] [blame] | 84 | This method is called to handle endtags for which an |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 85 | \method{end_\var{tag}()} method has been defined. The \var{tag} |
Guido van Rossum | a10768a | 1997-11-18 15:11:22 +0000 | [diff] [blame] | 86 | argument is the name of the tag, and the |
Fred Drake | 3b5da76 | 1998-03-12 15:33:05 +0000 | [diff] [blame] | 87 | \var{method} argument is the bound method which should be used to |
Guido van Rossum | a10768a | 1997-11-18 15:11:22 +0000 | [diff] [blame] | 88 | support semantic interpretation of the end tag. If no |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 89 | \method{end_\var{tag}()} method is defined for the closing element, this |
Guido van Rossum | a10768a | 1997-11-18 15:11:22 +0000 | [diff] [blame] | 90 | handler is not called. The base implementation simply calls |
Fred Drake | 3b5da76 | 1998-03-12 15:33:05 +0000 | [diff] [blame] | 91 | \var{method}. |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 92 | \end{methoddesc} |
Guido van Rossum | a10768a | 1997-11-18 15:11:22 +0000 | [diff] [blame] | 93 | |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 94 | \begin{methoddesc}{handle_data}{data} |
Guido van Rossum | a10768a | 1997-11-18 15:11:22 +0000 | [diff] [blame] | 95 | This method is called to process arbitrary data. It is intended to be |
| 96 | overridden by a derived class; the base class implementation does |
| 97 | nothing. |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 98 | \end{methoddesc} |
Guido van Rossum | a10768a | 1997-11-18 15:11:22 +0000 | [diff] [blame] | 99 | |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 100 | \begin{methoddesc}{handle_charref}{ref} |
Guido van Rossum | a10768a | 1997-11-18 15:11:22 +0000 | [diff] [blame] | 101 | This method is called to process a character reference of the form |
Fred Drake | 7f6e2c4 | 1998-02-13 14:38:23 +0000 | [diff] [blame] | 102 | \samp{\&\#\var{ref};}. \var{ref} can either be a decimal number, |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 103 | or a hexadecimal number when preceded by an \character{x}. |
Guido van Rossum | a10768a | 1997-11-18 15:11:22 +0000 | [diff] [blame] | 104 | In the base implementation, \var{ref} must be a number in the |
| 105 | range 0-255. It translates the character to \ASCII{} and calls the |
Fred Drake | 3b5da76 | 1998-03-12 15:33:05 +0000 | [diff] [blame] | 106 | method \method{handle_data()} with the character as argument. If |
Guido van Rossum | a10768a | 1997-11-18 15:11:22 +0000 | [diff] [blame] | 107 | \var{ref} is invalid or out of range, the method |
| 108 | \code{unknown_charref(\var{ref})} is called to handle the error. A |
| 109 | subclass must override this method to provide support for character |
| 110 | references outside of the \ASCII{} range. |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 111 | \end{methoddesc} |
Guido van Rossum | a10768a | 1997-11-18 15:11:22 +0000 | [diff] [blame] | 112 | |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 113 | \begin{methoddesc}{handle_entityref}{ref} |
Fred Drake | 3b5da76 | 1998-03-12 15:33:05 +0000 | [diff] [blame] | 114 | This method is called to process a general entity reference of the |
| 115 | form \samp{\&\var{ref};} where \var{ref} is an general entity |
Guido van Rossum | a10768a | 1997-11-18 15:11:22 +0000 | [diff] [blame] | 116 | reference. It looks for \var{ref} in the instance (or class) |
Fred Drake | 3b5da76 | 1998-03-12 15:33:05 +0000 | [diff] [blame] | 117 | variable \member{entitydefs} which should be a mapping from entity |
| 118 | names to corresponding translations. |
| 119 | If a translation is found, it calls the method \method{handle_data()} |
Guido van Rossum | a10768a | 1997-11-18 15:11:22 +0000 | [diff] [blame] | 120 | with the translation; otherwise, it calls the method |
Fred Drake | 3b5da76 | 1998-03-12 15:33:05 +0000 | [diff] [blame] | 121 | \code{unknown_entityref(\var{ref})}. The default \member{entitydefs} |
Guido van Rossum | a10768a | 1997-11-18 15:11:22 +0000 | [diff] [blame] | 122 | defines translations for \code{\&}, \code{\&apos}, \code{\>}, |
| 123 | \code{\<}, and \code{\"}. |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 124 | \end{methoddesc} |
Guido van Rossum | a10768a | 1997-11-18 15:11:22 +0000 | [diff] [blame] | 125 | |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 126 | \begin{methoddesc}{handle_comment}{comment} |
Guido van Rossum | a10768a | 1997-11-18 15:11:22 +0000 | [diff] [blame] | 127 | This method is called when a comment is encountered. The |
Fred Drake | 3b5da76 | 1998-03-12 15:33:05 +0000 | [diff] [blame] | 128 | \var{comment} argument is a string containing the text between the |
Fred Drake | 7f6e2c4 | 1998-02-13 14:38:23 +0000 | [diff] [blame] | 129 | \samp{<!--} and \samp{-->} delimiters, but not the delimiters |
| 130 | themselves. For example, the comment \samp{<!--text-->} will |
Guido van Rossum | a10768a | 1997-11-18 15:11:22 +0000 | [diff] [blame] | 131 | cause this method to be called with the argument \code{'text'}. The |
| 132 | default method does nothing. |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 133 | \end{methoddesc} |
Guido van Rossum | a10768a | 1997-11-18 15:11:22 +0000 | [diff] [blame] | 134 | |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 135 | \begin{methoddesc}{handle_cdata}{data} |
Guido van Rossum | a10768a | 1997-11-18 15:11:22 +0000 | [diff] [blame] | 136 | This method is called when a CDATA element is encountered. The |
Fred Drake | 3b5da76 | 1998-03-12 15:33:05 +0000 | [diff] [blame] | 137 | \var{data} argument is a string containing the text between the |
Fred Drake | 7f6e2c4 | 1998-02-13 14:38:23 +0000 | [diff] [blame] | 138 | \samp{<![CDATA[} and \samp{]]>} delimiters, but not the delimiters |
| 139 | themselves. For example, the entity \samp{<![CDATA[text]]>} will |
Guido van Rossum | a10768a | 1997-11-18 15:11:22 +0000 | [diff] [blame] | 140 | cause this method to be called with the argument \code{'text'}. The |
Fred Drake | 3b5da76 | 1998-03-12 15:33:05 +0000 | [diff] [blame] | 141 | default method does nothing, and is intended to be overridden. |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 142 | \end{methoddesc} |
Guido van Rossum | a10768a | 1997-11-18 15:11:22 +0000 | [diff] [blame] | 143 | |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 144 | \begin{methoddesc}{handle_proc}{name, data} |
Fred Drake | 3b5da76 | 1998-03-12 15:33:05 +0000 | [diff] [blame] | 145 | This method is called when a processing instruction (PI) is |
| 146 | encountered. The \var{name} is the PI target, and the \var{data} |
| 147 | argument is a string containing the text between the PI target and the |
| 148 | closing delimiter, but not the delimiter itself. For example, the |
| 149 | instruction \samp{<?XML text?>} will cause this method to be called |
| 150 | with the arguments \code{'XML'} and \code{'text'}. The default method |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 151 | does nothing. Note that if a document starts with \samp{<?xml |
Fred Drake | 3b5da76 | 1998-03-12 15:33:05 +0000 | [diff] [blame] | 152 | ...?>}, \method{handle_xml()} is called to handle it. |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 153 | \end{methoddesc} |
Guido van Rossum | a10768a | 1997-11-18 15:11:22 +0000 | [diff] [blame] | 154 | |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 155 | \begin{methoddesc}{handle_special}{data} |
Guido van Rossum | a10768a | 1997-11-18 15:11:22 +0000 | [diff] [blame] | 156 | This method is called when a declaration is encountered. The |
Fred Drake | 3b5da76 | 1998-03-12 15:33:05 +0000 | [diff] [blame] | 157 | \var{data} argument is a string containing the text between the |
Fred Drake | 7f6e2c4 | 1998-02-13 14:38:23 +0000 | [diff] [blame] | 158 | \samp{<!} and \samp{>} delimiters, but not the delimiters |
| 159 | themselves. For example, the entity \samp{<!ENTITY text>} will |
Guido van Rossum | 02505e4 | 1998-01-29 14:55:24 +0000 | [diff] [blame] | 160 | cause this method to be called with the argument \code{'ENTITY text'}. The |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 161 | default method does nothing. Note that \samp{<!DOCTYPE ...>} is |
Guido van Rossum | 02505e4 | 1998-01-29 14:55:24 +0000 | [diff] [blame] | 162 | handled separately if it is located at the start of the document. |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 163 | \end{methoddesc} |
Guido van Rossum | a10768a | 1997-11-18 15:11:22 +0000 | [diff] [blame] | 164 | |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 165 | \begin{methoddesc}{syntax_error}{message} |
Guido van Rossum | a10768a | 1997-11-18 15:11:22 +0000 | [diff] [blame] | 166 | This method is called when a syntax error is encountered. The |
Fred Drake | 3b5da76 | 1998-03-12 15:33:05 +0000 | [diff] [blame] | 167 | \var{message} is a description of what was wrong. The default method |
| 168 | raises a \exception{RuntimeError} exception. If this method is |
| 169 | overridden, it is permissable for it to return. This method is only |
| 170 | called when the error can be recovered from. Unrecoverable errors |
| 171 | raise a \exception{RuntimeError} without first calling |
| 172 | \method{syntax_error()}. |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 173 | \end{methoddesc} |
Guido van Rossum | a10768a | 1997-11-18 15:11:22 +0000 | [diff] [blame] | 174 | |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 175 | \begin{methoddesc}{unknown_starttag}{tag, attributes} |
Guido van Rossum | a10768a | 1997-11-18 15:11:22 +0000 | [diff] [blame] | 176 | This method is called to process an unknown start tag. It is intended |
| 177 | to be overridden by a derived class; the base class implementation |
| 178 | does nothing. |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 179 | \end{methoddesc} |
Guido van Rossum | a10768a | 1997-11-18 15:11:22 +0000 | [diff] [blame] | 180 | |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 181 | \begin{methoddesc}{unknown_endtag}{tag} |
Guido van Rossum | a10768a | 1997-11-18 15:11:22 +0000 | [diff] [blame] | 182 | This method is called to process an unknown end tag. It is intended |
| 183 | to be overridden by a derived class; the base class implementation |
| 184 | does nothing. |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 185 | \end{methoddesc} |
Guido van Rossum | a10768a | 1997-11-18 15:11:22 +0000 | [diff] [blame] | 186 | |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 187 | \begin{methoddesc}{unknown_charref}{ref} |
Guido van Rossum | a10768a | 1997-11-18 15:11:22 +0000 | [diff] [blame] | 188 | This method is called to process unresolvable numeric character |
| 189 | references. It is intended to be overridden by a derived class; the |
| 190 | base class implementation does nothing. |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 191 | \end{methoddesc} |
Guido van Rossum | a10768a | 1997-11-18 15:11:22 +0000 | [diff] [blame] | 192 | |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 193 | \begin{methoddesc}{unknown_entityref}{ref} |
Guido van Rossum | a10768a | 1997-11-18 15:11:22 +0000 | [diff] [blame] | 194 | This method is called to process an unknown entity reference. It is |
| 195 | intended to be overridden by a derived class; the base class |
| 196 | implementation does nothing. |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 197 | \end{methoddesc} |
Guido van Rossum | a10768a | 1997-11-18 15:11:22 +0000 | [diff] [blame] | 198 | |
| 199 | Apart from overriding or extending the methods listed above, derived |
Guido van Rossum | 02505e4 | 1998-01-29 14:55:24 +0000 | [diff] [blame] | 200 | classes may also define methods and variables of the following form to |
| 201 | define processing of specific tags. Tag names in the input stream are |
| 202 | case dependent; the \var{tag} occurring in method names must be in the |
Guido van Rossum | a10768a | 1997-11-18 15:11:22 +0000 | [diff] [blame] | 203 | correct case: |
| 204 | |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 205 | \begin{methoddescni}{start_\var{tag}}{attributes} |
Guido van Rossum | a10768a | 1997-11-18 15:11:22 +0000 | [diff] [blame] | 206 | This method is called to process an opening tag \var{tag}. The |
| 207 | \var{attributes} argument has the same meaning as described for |
Fred Drake | 3b5da76 | 1998-03-12 15:33:05 +0000 | [diff] [blame] | 208 | \method{handle_starttag()} above. In fact, the base implementation of |
| 209 | \method{handle_starttag()} calls this method. |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 210 | \end{methoddescni} |
Guido van Rossum | a10768a | 1997-11-18 15:11:22 +0000 | [diff] [blame] | 211 | |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 212 | \begin{methoddescni}{end_\var{tag}}{} |
Guido van Rossum | a10768a | 1997-11-18 15:11:22 +0000 | [diff] [blame] | 213 | This method is called to process a closing tag \var{tag}. |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 214 | \end{methoddescni} |
Guido van Rossum | 02505e4 | 1998-01-29 14:55:24 +0000 | [diff] [blame] | 215 | |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 216 | \begin{memberdescni}{\var{tag}_attributes} |
| 217 | If a class or instance variable \member{\var{tag}_attributes} exists, it |
Guido van Rossum | 02505e4 | 1998-01-29 14:55:24 +0000 | [diff] [blame] | 218 | should be a list or a dictionary. If a list, the elements of the list |
| 219 | are the valid attributes for the element \var{tag}; if a dictionary, |
| 220 | the keys are the valid attributes for the element \var{tag}, and the |
| 221 | values the default values of the attributes, or \code{None} if there |
| 222 | is no default. |
| 223 | In addition to the attributes that were present in the tag, the |
Fred Drake | 3b5da76 | 1998-03-12 15:33:05 +0000 | [diff] [blame] | 224 | attribute dictionary that is passed to \method{handle_starttag()} and |
| 225 | \method{unknown_starttag()} contains values for all attributes that |
| 226 | have a default value. |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 227 | \end{memberdescni} |