Fred Drake | 295da24 | 1998-08-10 19:42:37 +0000 | [diff] [blame] | 1 | \section{\module{xmllib} --- |
Fred Drake | 3425011 | 1999-02-19 23:45:06 +0000 | [diff] [blame^] | 2 | A parser for XML documents} |
| 3 | |
Fred Drake | b91e934 | 1998-07-23 17:59:49 +0000 | [diff] [blame] | 4 | \declaremodule{standard}{xmllib} |
Fred Drake | 3425011 | 1999-02-19 23:45:06 +0000 | [diff] [blame^] | 5 | \modulesynopsis{A parser for XML documents.} |
Fred Drake | 191f285 | 1998-12-22 18:06:02 +0000 | [diff] [blame] | 6 | \moduleauthor{Sjoerd Mullender}{Sjoerd.Mullender@cwi.nl} |
| 7 | \sectionauthor{Sjoerd Mullender}{Sjoerd.Mullender@cwi.nl} |
Fred Drake | b91e934 | 1998-07-23 17:59:49 +0000 | [diff] [blame] | 8 | |
Fred Drake | b91e934 | 1998-07-23 17:59:49 +0000 | [diff] [blame] | 9 | |
Guido van Rossum | a10768a | 1997-11-18 15:11:22 +0000 | [diff] [blame] | 10 | \index{XML} |
Fred Drake | 5cb48a4 | 1998-12-22 18:46:13 +0000 | [diff] [blame] | 11 | \index{Extensible Markup Language} |
| 12 | |
| 13 | \versionchanged{1.5.2} |
Guido van Rossum | a10768a | 1997-11-18 15:11:22 +0000 | [diff] [blame] | 14 | |
Fred Drake | 3b5da76 | 1998-03-12 15:33:05 +0000 | [diff] [blame] | 15 | This module defines a class \class{XMLParser} which serves as the basis |
Fred Drake | 5cb48a4 | 1998-12-22 18:46:13 +0000 | [diff] [blame] | 16 | for parsing text files formatted in XML (Extensible Markup Language). |
Guido van Rossum | a10768a | 1997-11-18 15:11:22 +0000 | [diff] [blame] | 17 | |
Fred Drake | 3b5da76 | 1998-03-12 15:33:05 +0000 | [diff] [blame] | 18 | \begin{classdesc}{XMLParser}{} |
| 19 | The \class{XMLParser} class must be instantiated without arguments. |
| 20 | \end{classdesc} |
| 21 | |
Guido van Rossum | b083a9f | 1998-12-18 20:17:13 +0000 | [diff] [blame] | 22 | This class provides the following interface methods and instance variables: |
| 23 | |
| 24 | \begin{memberdesc}{attributes} |
| 25 | A mapping of element names to mappings. The latter mapping maps |
| 26 | attribute names that are valid for the element to the default value of |
| 27 | the attribute, or if there is no default to \code{None}. The default |
Guido van Rossum | 09da65e | 1999-02-02 17:55:12 +0000 | [diff] [blame] | 28 | value is the empty dictionary. This variable is meant to be |
| 29 | overridden, not extended since the default is shared by all instances |
| 30 | of \class{XMLParser}. |
Guido van Rossum | b083a9f | 1998-12-18 20:17:13 +0000 | [diff] [blame] | 31 | \end{memberdesc} |
| 32 | |
| 33 | \begin{memberdesc}{elements} |
| 34 | A mapping of element names to tuples. The tuples contain a function |
| 35 | for handling the start and end tag respectively of the element, or |
| 36 | \code{None} if the method \method{unknown_starttag()} or |
| 37 | \method{unknown_endtag()} is to be called. The default value is the |
Guido van Rossum | 09da65e | 1999-02-02 17:55:12 +0000 | [diff] [blame] | 38 | empty dictionary. This variable is meant to be overridden, not |
| 39 | extended since the default is shared by all instances of |
| 40 | \class{XMLParser}. |
Guido van Rossum | b083a9f | 1998-12-18 20:17:13 +0000 | [diff] [blame] | 41 | \end{memberdesc} |
| 42 | |
| 43 | \begin{memberdesc}{entitydefs} |
| 44 | A mapping of entitynames to their values. The default value contains |
| 45 | definitions for \code{'lt'}, \code{'gt'}, \code{'amp'}, \code{'quot'}, |
| 46 | and \code{'apos'}. |
| 47 | \end{memberdesc} |
Guido van Rossum | a10768a | 1997-11-18 15:11:22 +0000 | [diff] [blame] | 48 | |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 49 | \begin{methoddesc}{reset}{} |
Guido van Rossum | a10768a | 1997-11-18 15:11:22 +0000 | [diff] [blame] | 50 | Reset the instance. Loses all unprocessed data. This is called |
| 51 | implicitly at the instantiation time. |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 52 | \end{methoddesc} |
Guido van Rossum | a10768a | 1997-11-18 15:11:22 +0000 | [diff] [blame] | 53 | |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 54 | \begin{methoddesc}{setnomoretags}{} |
Guido van Rossum | a10768a | 1997-11-18 15:11:22 +0000 | [diff] [blame] | 55 | Stop processing tags. Treat all following input as literal input |
| 56 | (CDATA). |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 57 | \end{methoddesc} |
Guido van Rossum | a10768a | 1997-11-18 15:11:22 +0000 | [diff] [blame] | 58 | |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 59 | \begin{methoddesc}{setliteral}{} |
Guido van Rossum | f484a33 | 1998-12-07 21:59:56 +0000 | [diff] [blame] | 60 | Enter literal mode (CDATA mode). This mode is automatically exited |
| 61 | when the close tag matching the last unclosed open tag is encountered. |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 62 | \end{methoddesc} |
Guido van Rossum | a10768a | 1997-11-18 15:11:22 +0000 | [diff] [blame] | 63 | |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 64 | \begin{methoddesc}{feed}{data} |
Guido van Rossum | a10768a | 1997-11-18 15:11:22 +0000 | [diff] [blame] | 65 | Feed some text to the parser. It is processed insofar as it consists |
Guido van Rossum | b083a9f | 1998-12-18 20:17:13 +0000 | [diff] [blame] | 66 | of complete tags; incomplete data is buffered until more data is |
Fred Drake | 3b5da76 | 1998-03-12 15:33:05 +0000 | [diff] [blame] | 67 | fed or \method{close()} is called. |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 68 | \end{methoddesc} |
Guido van Rossum | a10768a | 1997-11-18 15:11:22 +0000 | [diff] [blame] | 69 | |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 70 | \begin{methoddesc}{close}{} |
Guido van Rossum | a10768a | 1997-11-18 15:11:22 +0000 | [diff] [blame] | 71 | Force processing of all buffered data as if it were followed by an |
| 72 | end-of-file mark. This method may be redefined by a derived class to |
| 73 | define additional processing at the end of the input, but the |
Fred Drake | 3b5da76 | 1998-03-12 15:33:05 +0000 | [diff] [blame] | 74 | redefined version should always call \method{close()}. |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 75 | \end{methoddesc} |
Guido van Rossum | a10768a | 1997-11-18 15:11:22 +0000 | [diff] [blame] | 76 | |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 77 | \begin{methoddesc}{translate_references}{data} |
Fred Drake | 3b5da76 | 1998-03-12 15:33:05 +0000 | [diff] [blame] | 78 | Translate all entity and character references in \var{data} and |
Fred Drake | d8a41e6 | 1999-02-19 17:54:10 +0000 | [diff] [blame] | 79 | return the translated string. |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 80 | \end{methoddesc} |
Guido van Rossum | 02505e4 | 1998-01-29 14:55:24 +0000 | [diff] [blame] | 81 | |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 82 | \begin{methoddesc}{handle_xml}{encoding, standalone} |
| 83 | This method is called when the \samp{<?xml ...?>} tag is processed. |
Guido van Rossum | 02505e4 | 1998-01-29 14:55:24 +0000 | [diff] [blame] | 84 | The arguments are the values of the encoding and standalone attributes |
| 85 | in the tag. Both encoding and standalone are optional. The values |
Fred Drake | 3b5da76 | 1998-03-12 15:33:05 +0000 | [diff] [blame] | 86 | 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] | 87 | \code{'no'} respectively. |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 88 | \end{methoddesc} |
Guido van Rossum | 02505e4 | 1998-01-29 14:55:24 +0000 | [diff] [blame] | 89 | |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 90 | \begin{methoddesc}{handle_doctype}{tag, data} |
| 91 | This method is called when the \samp{<!DOCTYPE...>} tag is processed. |
Guido van Rossum | 02505e4 | 1998-01-29 14:55:24 +0000 | [diff] [blame] | 92 | The arguments are the name of the root element and the uninterpreted |
| 93 | contents of the tag, starting after the white space after the name of |
| 94 | the root element. |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 95 | \end{methoddesc} |
Guido van Rossum | 02505e4 | 1998-01-29 14:55:24 +0000 | [diff] [blame] | 96 | |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 97 | \begin{methoddesc}{handle_starttag}{tag, method, attributes} |
Guido van Rossum | b083a9f | 1998-12-18 20:17:13 +0000 | [diff] [blame] | 98 | This method is called to handle start tags for which a start tag |
| 99 | handler is defined in the instance variable \member{elements}. The |
| 100 | \var{tag} argument is the name of the tag, and the \var{method} |
| 101 | argument is the function (method) which should be used to support semantic |
| 102 | interpretation of the start tag. The \var{attributes} argument is a |
| 103 | dictionary of attributes, the key being the \var{name} and the value |
| 104 | being the \var{value} of the attribute found inside the tag's |
| 105 | \code{<>} brackets. Character and entity references in the |
| 106 | \var{value} have been interpreted. For instance, for the start tag |
Guido van Rossum | a10768a | 1997-11-18 15:11:22 +0000 | [diff] [blame] | 107 | \code{<A HREF="http://www.cwi.nl/">}, this method would be called as |
Guido van Rossum | b083a9f | 1998-12-18 20:17:13 +0000 | [diff] [blame] | 108 | \code{handle_starttag('A', self.elements['A'][0], \{'HREF': 'http://www.cwi.nl/'\})}. |
Fred Drake | 3b5da76 | 1998-03-12 15:33:05 +0000 | [diff] [blame] | 109 | The base implementation simply calls \var{method} with \var{attributes} |
Guido van Rossum | a10768a | 1997-11-18 15:11:22 +0000 | [diff] [blame] | 110 | as the only argument. |
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_endtag}{tag, method} |
Guido van Rossum | b083a9f | 1998-12-18 20:17:13 +0000 | [diff] [blame] | 114 | This method is called to handle endtags for which an end tag handler |
| 115 | is defined in the instance variable \member{elements}. The \var{tag} |
| 116 | argument is the name of the tag, and the \var{method} argument is the |
| 117 | function (method) which should be used to support semantic |
| 118 | interpretation of the end tag. For instance, for the endtag |
| 119 | \code{</A>}, this method would be called as \code{handle_endtag('A', |
| 120 | self.elements['A'][1])}. The base implementation simply calls |
Fred Drake | 3b5da76 | 1998-03-12 15:33:05 +0000 | [diff] [blame] | 121 | \var{method}. |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 122 | \end{methoddesc} |
Guido van Rossum | a10768a | 1997-11-18 15:11:22 +0000 | [diff] [blame] | 123 | |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 124 | \begin{methoddesc}{handle_data}{data} |
Guido van Rossum | a10768a | 1997-11-18 15:11:22 +0000 | [diff] [blame] | 125 | This method is called to process arbitrary data. It is intended to be |
| 126 | overridden by a derived class; the base class implementation does |
| 127 | nothing. |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 128 | \end{methoddesc} |
Guido van Rossum | a10768a | 1997-11-18 15:11:22 +0000 | [diff] [blame] | 129 | |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 130 | \begin{methoddesc}{handle_charref}{ref} |
Guido van Rossum | a10768a | 1997-11-18 15:11:22 +0000 | [diff] [blame] | 131 | This method is called to process a character reference of the form |
Fred Drake | 7f6e2c4 | 1998-02-13 14:38:23 +0000 | [diff] [blame] | 132 | \samp{\&\#\var{ref};}. \var{ref} can either be a decimal number, |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 133 | or a hexadecimal number when preceded by an \character{x}. |
Guido van Rossum | a10768a | 1997-11-18 15:11:22 +0000 | [diff] [blame] | 134 | In the base implementation, \var{ref} must be a number in the |
| 135 | range 0-255. It translates the character to \ASCII{} and calls the |
Fred Drake | 3b5da76 | 1998-03-12 15:33:05 +0000 | [diff] [blame] | 136 | method \method{handle_data()} with the character as argument. If |
Guido van Rossum | a10768a | 1997-11-18 15:11:22 +0000 | [diff] [blame] | 137 | \var{ref} is invalid or out of range, the method |
| 138 | \code{unknown_charref(\var{ref})} is called to handle the error. A |
| 139 | subclass must override this method to provide support for character |
| 140 | references outside of the \ASCII{} range. |
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_entityref}{ref} |
Fred Drake | 3b5da76 | 1998-03-12 15:33:05 +0000 | [diff] [blame] | 144 | This method is called to process a general entity reference of the |
| 145 | form \samp{\&\var{ref};} where \var{ref} is an general entity |
Guido van Rossum | a10768a | 1997-11-18 15:11:22 +0000 | [diff] [blame] | 146 | reference. It looks for \var{ref} in the instance (or class) |
Fred Drake | 3b5da76 | 1998-03-12 15:33:05 +0000 | [diff] [blame] | 147 | variable \member{entitydefs} which should be a mapping from entity |
| 148 | names to corresponding translations. |
| 149 | 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] | 150 | with the translation; otherwise, it calls the method |
Fred Drake | 3b5da76 | 1998-03-12 15:33:05 +0000 | [diff] [blame] | 151 | \code{unknown_entityref(\var{ref})}. The default \member{entitydefs} |
Guido van Rossum | a10768a | 1997-11-18 15:11:22 +0000 | [diff] [blame] | 152 | defines translations for \code{\&}, \code{\&apos}, \code{\>}, |
| 153 | \code{\<}, and \code{\"}. |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 154 | \end{methoddesc} |
Guido van Rossum | a10768a | 1997-11-18 15:11:22 +0000 | [diff] [blame] | 155 | |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 156 | \begin{methoddesc}{handle_comment}{comment} |
Guido van Rossum | a10768a | 1997-11-18 15:11:22 +0000 | [diff] [blame] | 157 | This method is called when a comment is encountered. The |
Fred Drake | 3b5da76 | 1998-03-12 15:33:05 +0000 | [diff] [blame] | 158 | \var{comment} argument is a string containing the text between the |
Fred Drake | 7f6e2c4 | 1998-02-13 14:38:23 +0000 | [diff] [blame] | 159 | \samp{<!--} and \samp{-->} delimiters, but not the delimiters |
| 160 | themselves. For example, the comment \samp{<!--text-->} will |
Guido van Rossum | a10768a | 1997-11-18 15:11:22 +0000 | [diff] [blame] | 161 | cause this method to be called with the argument \code{'text'}. The |
| 162 | default method does nothing. |
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}{handle_cdata}{data} |
Guido van Rossum | a10768a | 1997-11-18 15:11:22 +0000 | [diff] [blame] | 166 | This method is called when a CDATA element is encountered. The |
Fred Drake | 3b5da76 | 1998-03-12 15:33:05 +0000 | [diff] [blame] | 167 | \var{data} argument is a string containing the text between the |
Fred Drake | 7f6e2c4 | 1998-02-13 14:38:23 +0000 | [diff] [blame] | 168 | \samp{<![CDATA[} and \samp{]]>} delimiters, but not the delimiters |
| 169 | themselves. For example, the entity \samp{<![CDATA[text]]>} will |
Guido van Rossum | a10768a | 1997-11-18 15:11:22 +0000 | [diff] [blame] | 170 | cause this method to be called with the argument \code{'text'}. The |
Fred Drake | 3b5da76 | 1998-03-12 15:33:05 +0000 | [diff] [blame] | 171 | default method does nothing, and is intended to be overridden. |
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}{handle_proc}{name, data} |
Fred Drake | 3b5da76 | 1998-03-12 15:33:05 +0000 | [diff] [blame] | 175 | This method is called when a processing instruction (PI) is |
| 176 | encountered. The \var{name} is the PI target, and the \var{data} |
| 177 | argument is a string containing the text between the PI target and the |
| 178 | closing delimiter, but not the delimiter itself. For example, the |
| 179 | instruction \samp{<?XML text?>} will cause this method to be called |
| 180 | with the arguments \code{'XML'} and \code{'text'}. The default method |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 181 | does nothing. Note that if a document starts with \samp{<?xml |
Guido van Rossum | b083a9f | 1998-12-18 20:17:13 +0000 | [diff] [blame] | 182 | ..?>}, \method{handle_xml()} is called to handle it. |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 183 | \end{methoddesc} |
Guido van Rossum | a10768a | 1997-11-18 15:11:22 +0000 | [diff] [blame] | 184 | |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 185 | \begin{methoddesc}{handle_special}{data} |
Guido van Rossum | a10768a | 1997-11-18 15:11:22 +0000 | [diff] [blame] | 186 | This method is called when a declaration is encountered. The |
Fred Drake | 3b5da76 | 1998-03-12 15:33:05 +0000 | [diff] [blame] | 187 | \var{data} argument is a string containing the text between the |
Fred Drake | 7f6e2c4 | 1998-02-13 14:38:23 +0000 | [diff] [blame] | 188 | \samp{<!} and \samp{>} delimiters, but not the delimiters |
| 189 | themselves. For example, the entity \samp{<!ENTITY text>} will |
Guido van Rossum | 02505e4 | 1998-01-29 14:55:24 +0000 | [diff] [blame] | 190 | 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] | 191 | default method does nothing. Note that \samp{<!DOCTYPE ...>} is |
Guido van Rossum | 02505e4 | 1998-01-29 14:55:24 +0000 | [diff] [blame] | 192 | handled separately if it is located at the start of the document. |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 193 | \end{methoddesc} |
Guido van Rossum | a10768a | 1997-11-18 15:11:22 +0000 | [diff] [blame] | 194 | |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 195 | \begin{methoddesc}{syntax_error}{message} |
Guido van Rossum | a10768a | 1997-11-18 15:11:22 +0000 | [diff] [blame] | 196 | This method is called when a syntax error is encountered. The |
Fred Drake | 3b5da76 | 1998-03-12 15:33:05 +0000 | [diff] [blame] | 197 | \var{message} is a description of what was wrong. The default method |
| 198 | raises a \exception{RuntimeError} exception. If this method is |
| 199 | overridden, it is permissable for it to return. This method is only |
| 200 | called when the error can be recovered from. Unrecoverable errors |
| 201 | raise a \exception{RuntimeError} without first calling |
| 202 | \method{syntax_error()}. |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 203 | \end{methoddesc} |
Guido van Rossum | a10768a | 1997-11-18 15:11:22 +0000 | [diff] [blame] | 204 | |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 205 | \begin{methoddesc}{unknown_starttag}{tag, attributes} |
Guido van Rossum | a10768a | 1997-11-18 15:11:22 +0000 | [diff] [blame] | 206 | This method is called to process an unknown start tag. It is intended |
| 207 | to be overridden by a derived class; the base class implementation |
| 208 | does nothing. |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 209 | \end{methoddesc} |
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{methoddesc}{unknown_endtag}{tag} |
Guido van Rossum | a10768a | 1997-11-18 15:11:22 +0000 | [diff] [blame] | 212 | This method is called to process an unknown end tag. It is intended |
| 213 | to be overridden by a derived class; the base class implementation |
| 214 | does nothing. |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 215 | \end{methoddesc} |
Guido van Rossum | a10768a | 1997-11-18 15:11:22 +0000 | [diff] [blame] | 216 | |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 217 | \begin{methoddesc}{unknown_charref}{ref} |
Guido van Rossum | a10768a | 1997-11-18 15:11:22 +0000 | [diff] [blame] | 218 | This method is called to process unresolvable numeric character |
| 219 | references. It is intended to be overridden by a derived class; the |
| 220 | base class implementation does nothing. |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 221 | \end{methoddesc} |
Guido van Rossum | a10768a | 1997-11-18 15:11:22 +0000 | [diff] [blame] | 222 | |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 223 | \begin{methoddesc}{unknown_entityref}{ref} |
Guido van Rossum | a10768a | 1997-11-18 15:11:22 +0000 | [diff] [blame] | 224 | This method is called to process an unknown entity reference. It is |
| 225 | intended to be overridden by a derived class; the base class |
| 226 | implementation does nothing. |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 227 | \end{methoddesc} |
Guido van Rossum | a10768a | 1997-11-18 15:11:22 +0000 | [diff] [blame] | 228 | |
Fred Drake | 3425011 | 1999-02-19 23:45:06 +0000 | [diff] [blame^] | 229 | |
| 230 | \subsection{XML Namespaces \label{xml-namespace}} |
Guido van Rossum | a10768a | 1997-11-18 15:11:22 +0000 | [diff] [blame] | 231 | |
Guido van Rossum | b083a9f | 1998-12-18 20:17:13 +0000 | [diff] [blame] | 232 | This module has support for XML namespaces as defined in the XML |
| 233 | Namespaces proposed recommendation. |
Fred Drake | 3425011 | 1999-02-19 23:45:06 +0000 | [diff] [blame^] | 234 | \indexii{XML}{namespaces} |
Guido van Rossum | a10768a | 1997-11-18 15:11:22 +0000 | [diff] [blame] | 235 | |
Guido van Rossum | b083a9f | 1998-12-18 20:17:13 +0000 | [diff] [blame] | 236 | Tag and attribute names that are defined in an XML namespace are |
| 237 | handled as if the name of the tag or element consisted of the |
| 238 | namespace (i.e. the URL that defines the namespace) followed by a |
| 239 | space and the name of the tag or attribute. For instance, the tag |
| 240 | \code{<html xmlns='http://www.w3.org/TR/REC-html40'>} is treated as if |
| 241 | the tag name was \code{'http://www.w3.org/TR/REC-html40 html'}, and |
| 242 | the tag \code{<html:a href='http://frob.com'>} inside the above |
| 243 | mentioned element is treated as if the tag name were |
| 244 | \code{'http://www.w3.org/TR/REC-html40 a'} and the attribute name as |
| 245 | if it were \code{'http://www.w3.org/TR/REC-html40 src'}. |
Guido van Rossum | 02505e4 | 1998-01-29 14:55:24 +0000 | [diff] [blame] | 246 | |
Guido van Rossum | b083a9f | 1998-12-18 20:17:13 +0000 | [diff] [blame] | 247 | An older draft of the XML Namespaces proposal is also recognized, but |
| 248 | triggers a warning. |