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