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}{} |
Guido van Rossum | e7f1920 | 1999-08-26 15:57:44 +0000 | [diff] [blame] | 19 | The \class{XMLParser} class must be instantiated without |
| 20 | arguments.\footnote{Actually, a number of keyword arguments are |
| 21 | recognized which influence the parser to accept certain non-standard |
| 22 | constructs. The following keyword arguments are currently |
Fred Drake | 011028c | 2000-07-06 04:45:14 +0000 | [diff] [blame] | 23 | recognized. The defaults for all of these is \code{0} (false) except |
| 24 | for the last one for which the default is \code{1} (true). |
Guido van Rossum | e7f1920 | 1999-08-26 15:57:44 +0000 | [diff] [blame] | 25 | \var{accept_unquoted_attributes} (accept certain attribute values |
| 26 | without requiring quotes), \var{accept_missing_endtag_name} (accept |
| 27 | end tags that look like \code{</>}), \var{map_case} (map upper case to |
| 28 | lower case in tags and attributes), \var{accept_utf8} (allow UTF-8 |
| 29 | characters in input; this is required according to the XML standard, |
| 30 | but Python does not as yet deal properly with these characters, so |
Fred Drake | 011028c | 2000-07-06 04:45:14 +0000 | [diff] [blame] | 31 | this is not the default), \var{translate_attribute_references} (don't |
| 32 | attempt to translate character and entity references in attribute values).} |
Fred Drake | 3b5da76 | 1998-03-12 15:33:05 +0000 | [diff] [blame] | 33 | \end{classdesc} |
| 34 | |
Guido van Rossum | b083a9f | 1998-12-18 20:17:13 +0000 | [diff] [blame] | 35 | This class provides the following interface methods and instance variables: |
| 36 | |
| 37 | \begin{memberdesc}{attributes} |
| 38 | A mapping of element names to mappings. The latter mapping maps |
| 39 | attribute names that are valid for the element to the default value of |
| 40 | 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] | 41 | value is the empty dictionary. This variable is meant to be |
| 42 | overridden, not extended since the default is shared by all instances |
| 43 | of \class{XMLParser}. |
Guido van Rossum | b083a9f | 1998-12-18 20:17:13 +0000 | [diff] [blame] | 44 | \end{memberdesc} |
| 45 | |
| 46 | \begin{memberdesc}{elements} |
| 47 | A mapping of element names to tuples. The tuples contain a function |
| 48 | for handling the start and end tag respectively of the element, or |
| 49 | \code{None} if the method \method{unknown_starttag()} or |
| 50 | \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] | 51 | empty dictionary. This variable is meant to be overridden, not |
| 52 | extended since the default is shared by all instances of |
| 53 | \class{XMLParser}. |
Guido van Rossum | b083a9f | 1998-12-18 20:17:13 +0000 | [diff] [blame] | 54 | \end{memberdesc} |
| 55 | |
| 56 | \begin{memberdesc}{entitydefs} |
| 57 | A mapping of entitynames to their values. The default value contains |
| 58 | definitions for \code{'lt'}, \code{'gt'}, \code{'amp'}, \code{'quot'}, |
| 59 | and \code{'apos'}. |
| 60 | \end{memberdesc} |
Guido van Rossum | a10768a | 1997-11-18 15:11:22 +0000 | [diff] [blame] | 61 | |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 62 | \begin{methoddesc}{reset}{} |
Guido van Rossum | a10768a | 1997-11-18 15:11:22 +0000 | [diff] [blame] | 63 | Reset the instance. Loses all unprocessed data. This is called |
| 64 | implicitly at the instantiation time. |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 65 | \end{methoddesc} |
Guido van Rossum | a10768a | 1997-11-18 15:11:22 +0000 | [diff] [blame] | 66 | |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 67 | \begin{methoddesc}{setnomoretags}{} |
Guido van Rossum | a10768a | 1997-11-18 15:11:22 +0000 | [diff] [blame] | 68 | Stop processing tags. Treat all following input as literal input |
| 69 | (CDATA). |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 70 | \end{methoddesc} |
Guido van Rossum | a10768a | 1997-11-18 15:11:22 +0000 | [diff] [blame] | 71 | |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 72 | \begin{methoddesc}{setliteral}{} |
Guido van Rossum | f484a33 | 1998-12-07 21:59:56 +0000 | [diff] [blame] | 73 | Enter literal mode (CDATA mode). This mode is automatically exited |
| 74 | when the close tag matching the last unclosed open tag is encountered. |
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}{feed}{data} |
Guido van Rossum | a10768a | 1997-11-18 15:11:22 +0000 | [diff] [blame] | 78 | 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] | 79 | of complete tags; incomplete data is buffered until more data is |
Fred Drake | 3b5da76 | 1998-03-12 15:33:05 +0000 | [diff] [blame] | 80 | fed or \method{close()} is called. |
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}{close}{} |
Guido van Rossum | a10768a | 1997-11-18 15:11:22 +0000 | [diff] [blame] | 84 | Force processing of all buffered data as if it were followed by an |
| 85 | end-of-file mark. This method may be redefined by a derived class to |
| 86 | define additional processing at the end of the input, but the |
Fred Drake | 3b5da76 | 1998-03-12 15:33:05 +0000 | [diff] [blame] | 87 | redefined version should always call \method{close()}. |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 88 | \end{methoddesc} |
Guido van Rossum | a10768a | 1997-11-18 15:11:22 +0000 | [diff] [blame] | 89 | |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 90 | \begin{methoddesc}{translate_references}{data} |
Fred Drake | 3b5da76 | 1998-03-12 15:33:05 +0000 | [diff] [blame] | 91 | Translate all entity and character references in \var{data} and |
Fred Drake | d8a41e6 | 1999-02-19 17:54:10 +0000 | [diff] [blame] | 92 | return the translated string. |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 93 | \end{methoddesc} |
Guido van Rossum | 02505e4 | 1998-01-29 14:55:24 +0000 | [diff] [blame] | 94 | |
Sjoerd Mullender | 1c8feae | 2000-08-31 10:27:00 +0000 | [diff] [blame] | 95 | \begin{methoddesc}{getnamespace}{} |
| 96 | Return a mapping of namespace abbreviations to namespace URIs that are |
| 97 | currently in effect. |
| 98 | \end{methoddesc} |
| 99 | |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 100 | \begin{methoddesc}{handle_xml}{encoding, standalone} |
| 101 | This method is called when the \samp{<?xml ...?>} tag is processed. |
Guido van Rossum | 02505e4 | 1998-01-29 14:55:24 +0000 | [diff] [blame] | 102 | The arguments are the values of the encoding and standalone attributes |
| 103 | in the tag. Both encoding and standalone are optional. The values |
Fred Drake | 3b5da76 | 1998-03-12 15:33:05 +0000 | [diff] [blame] | 104 | 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] | 105 | \code{'no'} respectively. |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 106 | \end{methoddesc} |
Guido van Rossum | 02505e4 | 1998-01-29 14:55:24 +0000 | [diff] [blame] | 107 | |
Fred Drake | 38e5d27 | 2000-04-03 20:13:55 +0000 | [diff] [blame] | 108 | \begin{methoddesc}{handle_doctype}{tag, pubid, syslit, data} |
Fred Drake | 46479d3 | 2000-08-11 20:34:27 +0000 | [diff] [blame] | 109 | This\index{DOCTYPE declaration} method is called when the |
| 110 | \samp{<!DOCTYPE...>} declaration is processed. The arguments are the |
| 111 | tag name of the root element, the Formal Public\index{Formal Public |
| 112 | Identifier} Identifier (or \code{None} if not specified), the system |
| 113 | identifier, and the uninterpreted contents of the internal DTD subset |
| 114 | as a string (or \code{None} if not present). |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 115 | \end{methoddesc} |
Guido van Rossum | 02505e4 | 1998-01-29 14:55:24 +0000 | [diff] [blame] | 116 | |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 117 | \begin{methoddesc}{handle_starttag}{tag, method, attributes} |
Guido van Rossum | b083a9f | 1998-12-18 20:17:13 +0000 | [diff] [blame] | 118 | This method is called to handle start tags for which a start tag |
| 119 | handler is defined in the instance variable \member{elements}. The |
Fred Drake | 46479d3 | 2000-08-11 20:34:27 +0000 | [diff] [blame] | 120 | \var{tag} argument is the name of the tag, and the |
| 121 | \var{method} argument is the function (method) which should be used to |
| 122 | support semantic interpretation of the start tag. The |
| 123 | \var{attributes} argument is a dictionary of attributes, the key being |
| 124 | the \var{name} and the value being the \var{value} of the attribute |
| 125 | found inside the tag's \code{<>} brackets. Character and entity |
| 126 | references in the \var{value} have been interpreted. For instance, |
| 127 | for the start tag \code{<A HREF="http://www.cwi.nl/">}, this method |
| 128 | would be called as \code{handle_starttag('A', self.elements['A'][0], |
| 129 | \{'HREF': 'http://www.cwi.nl/'\})}. The base implementation simply |
| 130 | calls \var{method} with \var{attributes} as the only argument. |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 131 | \end{methoddesc} |
Guido van Rossum | a10768a | 1997-11-18 15:11:22 +0000 | [diff] [blame] | 132 | |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 133 | \begin{methoddesc}{handle_endtag}{tag, method} |
Guido van Rossum | b083a9f | 1998-12-18 20:17:13 +0000 | [diff] [blame] | 134 | This method is called to handle endtags for which an end tag handler |
| 135 | is defined in the instance variable \member{elements}. The \var{tag} |
| 136 | argument is the name of the tag, and the \var{method} argument is the |
| 137 | function (method) which should be used to support semantic |
| 138 | interpretation of the end tag. For instance, for the endtag |
| 139 | \code{</A>}, this method would be called as \code{handle_endtag('A', |
| 140 | self.elements['A'][1])}. The base implementation simply calls |
Fred Drake | 3b5da76 | 1998-03-12 15:33:05 +0000 | [diff] [blame] | 141 | \var{method}. |
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_data}{data} |
Guido van Rossum | a10768a | 1997-11-18 15:11:22 +0000 | [diff] [blame] | 145 | This method is called to process arbitrary data. It is intended to be |
| 146 | overridden by a derived class; the base class implementation does |
| 147 | nothing. |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 148 | \end{methoddesc} |
Guido van Rossum | a10768a | 1997-11-18 15:11:22 +0000 | [diff] [blame] | 149 | |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 150 | \begin{methoddesc}{handle_charref}{ref} |
Guido van Rossum | a10768a | 1997-11-18 15:11:22 +0000 | [diff] [blame] | 151 | This method is called to process a character reference of the form |
Fred Drake | 7f6e2c4 | 1998-02-13 14:38:23 +0000 | [diff] [blame] | 152 | \samp{\&\#\var{ref};}. \var{ref} can either be a decimal number, |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 153 | or a hexadecimal number when preceded by an \character{x}. |
Guido van Rossum | a10768a | 1997-11-18 15:11:22 +0000 | [diff] [blame] | 154 | In the base implementation, \var{ref} must be a number in the |
| 155 | range 0-255. It translates the character to \ASCII{} and calls the |
Fred Drake | 3b5da76 | 1998-03-12 15:33:05 +0000 | [diff] [blame] | 156 | method \method{handle_data()} with the character as argument. If |
Guido van Rossum | a10768a | 1997-11-18 15:11:22 +0000 | [diff] [blame] | 157 | \var{ref} is invalid or out of range, the method |
| 158 | \code{unknown_charref(\var{ref})} is called to handle the error. A |
| 159 | subclass must override this method to provide support for character |
| 160 | references outside of the \ASCII{} range. |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 161 | \end{methoddesc} |
Guido van Rossum | a10768a | 1997-11-18 15:11:22 +0000 | [diff] [blame] | 162 | |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 163 | \begin{methoddesc}{handle_comment}{comment} |
Guido van Rossum | a10768a | 1997-11-18 15:11:22 +0000 | [diff] [blame] | 164 | This method is called when a comment is encountered. The |
Fred Drake | 3b5da76 | 1998-03-12 15:33:05 +0000 | [diff] [blame] | 165 | \var{comment} argument is a string containing the text between the |
Fred Drake | 7f6e2c4 | 1998-02-13 14:38:23 +0000 | [diff] [blame] | 166 | \samp{<!--} and \samp{-->} delimiters, but not the delimiters |
| 167 | themselves. For example, the comment \samp{<!--text-->} will |
Guido van Rossum | a10768a | 1997-11-18 15:11:22 +0000 | [diff] [blame] | 168 | cause this method to be called with the argument \code{'text'}. The |
| 169 | default method does nothing. |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 170 | \end{methoddesc} |
Guido van Rossum | a10768a | 1997-11-18 15:11:22 +0000 | [diff] [blame] | 171 | |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 172 | \begin{methoddesc}{handle_cdata}{data} |
Guido van Rossum | a10768a | 1997-11-18 15:11:22 +0000 | [diff] [blame] | 173 | This method is called when a CDATA element is encountered. The |
Fred Drake | 3b5da76 | 1998-03-12 15:33:05 +0000 | [diff] [blame] | 174 | \var{data} argument is a string containing the text between the |
Fred Drake | 7f6e2c4 | 1998-02-13 14:38:23 +0000 | [diff] [blame] | 175 | \samp{<![CDATA[} and \samp{]]>} delimiters, but not the delimiters |
| 176 | themselves. For example, the entity \samp{<![CDATA[text]]>} will |
Guido van Rossum | a10768a | 1997-11-18 15:11:22 +0000 | [diff] [blame] | 177 | cause this method to be called with the argument \code{'text'}. The |
Fred Drake | 3b5da76 | 1998-03-12 15:33:05 +0000 | [diff] [blame] | 178 | default method does nothing, and is intended to be overridden. |
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}{handle_proc}{name, data} |
Fred Drake | 3b5da76 | 1998-03-12 15:33:05 +0000 | [diff] [blame] | 182 | This method is called when a processing instruction (PI) is |
| 183 | encountered. The \var{name} is the PI target, and the \var{data} |
| 184 | argument is a string containing the text between the PI target and the |
| 185 | closing delimiter, but not the delimiter itself. For example, the |
| 186 | instruction \samp{<?XML text?>} will cause this method to be called |
| 187 | with the arguments \code{'XML'} and \code{'text'}. The default method |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 188 | does nothing. Note that if a document starts with \samp{<?xml |
Guido van Rossum | b083a9f | 1998-12-18 20:17:13 +0000 | [diff] [blame] | 189 | ..?>}, \method{handle_xml()} is called to handle it. |
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}{handle_special}{data} |
Guido van Rossum | a10768a | 1997-11-18 15:11:22 +0000 | [diff] [blame] | 193 | This method is called when a declaration is encountered. The |
Fred Drake | 3b5da76 | 1998-03-12 15:33:05 +0000 | [diff] [blame] | 194 | \var{data} argument is a string containing the text between the |
Fred Drake | 7f6e2c4 | 1998-02-13 14:38:23 +0000 | [diff] [blame] | 195 | \samp{<!} and \samp{>} delimiters, but not the delimiters |
Fred Drake | 46479d3 | 2000-08-11 20:34:27 +0000 | [diff] [blame] | 196 | themselves. For example, the \index{ENTITY declaration}entity |
| 197 | declaration \samp{<!ENTITY text>} will cause this method to be called |
| 198 | with the argument \code{'ENTITY text'}. The default method does |
| 199 | nothing. Note that \samp{<!DOCTYPE ...>} is handled separately if it |
| 200 | is located at the start of the document. |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 201 | \end{methoddesc} |
Guido van Rossum | a10768a | 1997-11-18 15:11:22 +0000 | [diff] [blame] | 202 | |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 203 | \begin{methoddesc}{syntax_error}{message} |
Guido van Rossum | a10768a | 1997-11-18 15:11:22 +0000 | [diff] [blame] | 204 | This method is called when a syntax error is encountered. The |
Fred Drake | 3b5da76 | 1998-03-12 15:33:05 +0000 | [diff] [blame] | 205 | \var{message} is a description of what was wrong. The default method |
| 206 | raises a \exception{RuntimeError} exception. If this method is |
Thomas Wouters | f831663 | 2000-07-16 19:01:10 +0000 | [diff] [blame] | 207 | overridden, it is permissible for it to return. This method is only |
Fred Drake | 3b5da76 | 1998-03-12 15:33:05 +0000 | [diff] [blame] | 208 | called when the error can be recovered from. Unrecoverable errors |
| 209 | raise a \exception{RuntimeError} without first calling |
| 210 | \method{syntax_error()}. |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 211 | \end{methoddesc} |
Guido van Rossum | a10768a | 1997-11-18 15:11:22 +0000 | [diff] [blame] | 212 | |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 213 | \begin{methoddesc}{unknown_starttag}{tag, attributes} |
Guido van Rossum | a10768a | 1997-11-18 15:11:22 +0000 | [diff] [blame] | 214 | This method is called to process an unknown start tag. It is intended |
| 215 | to be overridden by a derived class; the base class implementation |
| 216 | does nothing. |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 217 | \end{methoddesc} |
Guido van Rossum | a10768a | 1997-11-18 15:11:22 +0000 | [diff] [blame] | 218 | |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 219 | \begin{methoddesc}{unknown_endtag}{tag} |
Guido van Rossum | a10768a | 1997-11-18 15:11:22 +0000 | [diff] [blame] | 220 | This method is called to process an unknown end tag. It is intended |
| 221 | to be overridden by a derived class; the base class implementation |
| 222 | does nothing. |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 223 | \end{methoddesc} |
Guido van Rossum | a10768a | 1997-11-18 15:11:22 +0000 | [diff] [blame] | 224 | |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 225 | \begin{methoddesc}{unknown_charref}{ref} |
Guido van Rossum | a10768a | 1997-11-18 15:11:22 +0000 | [diff] [blame] | 226 | This method is called to process unresolvable numeric character |
| 227 | references. It is intended to be overridden by a derived class; the |
| 228 | base class implementation does nothing. |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 229 | \end{methoddesc} |
Guido van Rossum | a10768a | 1997-11-18 15:11:22 +0000 | [diff] [blame] | 230 | |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 231 | \begin{methoddesc}{unknown_entityref}{ref} |
Guido van Rossum | a10768a | 1997-11-18 15:11:22 +0000 | [diff] [blame] | 232 | This method is called to process an unknown entity reference. It is |
| 233 | intended to be overridden by a derived class; the base class |
Guido van Rossum | e7f1920 | 1999-08-26 15:57:44 +0000 | [diff] [blame] | 234 | implementation calls \method{syntax_error()} to signal an error. |
Fred Drake | fc57619 | 1998-04-04 07:15:02 +0000 | [diff] [blame] | 235 | \end{methoddesc} |
Guido van Rossum | a10768a | 1997-11-18 15:11:22 +0000 | [diff] [blame] | 236 | |
Fred Drake | 3425011 | 1999-02-19 23:45:06 +0000 | [diff] [blame] | 237 | |
Fred Drake | c8c40ff | 1999-04-22 20:16:02 +0000 | [diff] [blame] | 238 | \begin{seealso} |
Fred Drake | ae86d43 | 2000-09-12 17:53:48 +0000 | [diff] [blame] | 239 | \seetitle[http://www.w3.org/TR/REC-xml]{Extensible Markup Language |
| 240 | (XML) 1.0}{The XML specification, published by the World |
| 241 | Wide Web Consortium (W3C), defines the syntax and |
| 242 | processor requirements for XML. References to additional |
| 243 | material on XML, including translations of the |
| 244 | specification, are available at |
| 245 | \url{http://www.w3.org/XML/}.} |
Fred Drake | 38e5d27 | 2000-04-03 20:13:55 +0000 | [diff] [blame] | 246 | |
Fred Drake | ae86d43 | 2000-09-12 17:53:48 +0000 | [diff] [blame] | 247 | \seetitle[http://www.python.org/topics/xml/]{Python and XML |
| 248 | Processing}{The Python XML Topic Guide provides a great |
| 249 | deal of information on using XML from Python and links to |
| 250 | other sources of information on XML.} |
Fred Drake | c8c40ff | 1999-04-22 20:16:02 +0000 | [diff] [blame] | 251 | |
Fred Drake | ae86d43 | 2000-09-12 17:53:48 +0000 | [diff] [blame] | 252 | \seetitle[http://www.python.org/sigs/xml-sig/]{SIG for XML |
| 253 | Processing in Python}{The Python XML Special Interest |
| 254 | Group is developing substantial support for processing XML |
| 255 | from Python.} |
Fred Drake | c8c40ff | 1999-04-22 20:16:02 +0000 | [diff] [blame] | 256 | \end{seealso} |
| 257 | |
| 258 | |
Fred Drake | 3425011 | 1999-02-19 23:45:06 +0000 | [diff] [blame] | 259 | \subsection{XML Namespaces \label{xml-namespace}} |
Guido van Rossum | a10768a | 1997-11-18 15:11:22 +0000 | [diff] [blame] | 260 | |
Guido van Rossum | b083a9f | 1998-12-18 20:17:13 +0000 | [diff] [blame] | 261 | This module has support for XML namespaces as defined in the XML |
| 262 | Namespaces proposed recommendation. |
Fred Drake | 3425011 | 1999-02-19 23:45:06 +0000 | [diff] [blame] | 263 | \indexii{XML}{namespaces} |
Guido van Rossum | a10768a | 1997-11-18 15:11:22 +0000 | [diff] [blame] | 264 | |
Guido van Rossum | b083a9f | 1998-12-18 20:17:13 +0000 | [diff] [blame] | 265 | Tag and attribute names that are defined in an XML namespace are |
| 266 | handled as if the name of the tag or element consisted of the |
| 267 | namespace (i.e. the URL that defines the namespace) followed by a |
| 268 | space and the name of the tag or attribute. For instance, the tag |
| 269 | \code{<html xmlns='http://www.w3.org/TR/REC-html40'>} is treated as if |
| 270 | the tag name was \code{'http://www.w3.org/TR/REC-html40 html'}, and |
| 271 | the tag \code{<html:a href='http://frob.com'>} inside the above |
| 272 | mentioned element is treated as if the tag name were |
| 273 | \code{'http://www.w3.org/TR/REC-html40 a'} and the attribute name as |
| 274 | 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] | 275 | |
Guido van Rossum | b083a9f | 1998-12-18 20:17:13 +0000 | [diff] [blame] | 276 | An older draft of the XML Namespaces proposal is also recognized, but |
| 277 | triggers a warning. |
Fred Drake | ae86d43 | 2000-09-12 17:53:48 +0000 | [diff] [blame] | 278 | |
| 279 | \begin{seealso} |
| 280 | \seetitle[http://www.w3.org/TR/REC-xml-names/]{Namespaces in XML}{ |
| 281 | This World-Wide Web Consortium recommendation describes the |
| 282 | proper syntax and processing requirements for namespaces in |
| 283 | XML.} |
| 284 | \end{seealso} |