| Fred Drake | 7fbc85c | 2000-09-23 04:47:56 +0000 | [diff] [blame] | 1 | \section{\module{xml.parsers.expat} --- | 
| Fred Drake | efffe8e | 2000-10-29 05:10:30 +0000 | [diff] [blame] | 2 |          Fast XML parsing using Expat} | 
| Andrew M. Kuchling | 6b14eeb | 2000-06-11 02:42:07 +0000 | [diff] [blame] | 3 |  | 
| Fred Drake | 5ed1dac | 2001-02-08 15:40:33 +0000 | [diff] [blame] | 4 | % Markup notes: | 
 | 5 | % | 
 | 6 | % Many of the attributes of the XMLParser objects are callbacks. | 
 | 7 | % Since signature information must be presented, these are described | 
 | 8 | % using the methoddesc environment.  Since they are attributes which | 
 | 9 | % are set by client code, in-text references to these attributes | 
 | 10 | % should be marked using the \member macro and should not include the | 
 | 11 | % parentheses used when marking functions and methods. | 
 | 12 |  | 
| Fred Drake | 7fbc85c | 2000-09-23 04:47:56 +0000 | [diff] [blame] | 13 | \declaremodule{standard}{xml.parsers.expat} | 
 | 14 | \modulesynopsis{An interface to the Expat non-validating XML parser.} | 
| Andrew M. Kuchling | 6b14eeb | 2000-06-11 02:42:07 +0000 | [diff] [blame] | 15 | \moduleauthor{Paul Prescod}{paul@prescod.net} | 
| Andrew M. Kuchling | 6b14eeb | 2000-06-11 02:42:07 +0000 | [diff] [blame] | 16 |  | 
| Fred Drake | 7fbc85c | 2000-09-23 04:47:56 +0000 | [diff] [blame] | 17 | \versionadded{2.0} | 
 | 18 |  | 
| Fred Drake | efffe8e | 2000-10-29 05:10:30 +0000 | [diff] [blame] | 19 | The \module{xml.parsers.expat} module is a Python interface to the | 
 | 20 | Expat\index{Expat} non-validating XML parser. | 
| Andrew M. Kuchling | 6b14eeb | 2000-06-11 02:42:07 +0000 | [diff] [blame] | 21 | The module provides a single extension type, \class{xmlparser}, that | 
 | 22 | represents the current state of an XML parser.  After an | 
 | 23 | \class{xmlparser} object has been created, various attributes of the object  | 
 | 24 | can be set to handler functions.  When an XML document is then fed to | 
 | 25 | the parser, the handler functions are called for the character data | 
 | 26 | and markup in the XML document. | 
| Fred Drake | 7fbc85c | 2000-09-23 04:47:56 +0000 | [diff] [blame] | 27 |  | 
 | 28 | This module uses the \module{pyexpat}\refbimodindex{pyexpat} module to | 
 | 29 | provide access to the Expat parser.  Direct use of the | 
 | 30 | \module{pyexpat} module is deprecated. | 
| Fred Drake | efffe8e | 2000-10-29 05:10:30 +0000 | [diff] [blame] | 31 |  | 
 | 32 | This module provides one exception and one type object: | 
 | 33 |  | 
| Fred Drake | 1d8ad2b | 2001-02-14 18:54:32 +0000 | [diff] [blame] | 34 | \begin{excdesc}{ExpatError} | 
| Fred Drake | e0af35e | 2001-09-20 20:43:28 +0000 | [diff] [blame] | 35 |   The exception raised when Expat reports an error.  See section | 
 | 36 |   \ref{expaterror-objects}, ``ExpatError Exceptions,'' for more | 
 | 37 |   information on interpreting Expat errors. | 
| Fred Drake | efffe8e | 2000-10-29 05:10:30 +0000 | [diff] [blame] | 38 | \end{excdesc} | 
 | 39 |  | 
| Fred Drake | 1d8ad2b | 2001-02-14 18:54:32 +0000 | [diff] [blame] | 40 | \begin{excdesc}{error} | 
 | 41 |   Alias for \exception{ExpatError}. | 
 | 42 | \end{excdesc} | 
 | 43 |  | 
| Fred Drake | efffe8e | 2000-10-29 05:10:30 +0000 | [diff] [blame] | 44 | \begin{datadesc}{XMLParserType} | 
 | 45 |   The type of the return values from the \function{ParserCreate()} | 
 | 46 |   function. | 
 | 47 | \end{datadesc} | 
 | 48 |  | 
 | 49 |  | 
| Fred Drake | 7fbc85c | 2000-09-23 04:47:56 +0000 | [diff] [blame] | 50 | The \module{xml.parsers.expat} module contains two functions: | 
| Andrew M. Kuchling | 6b14eeb | 2000-06-11 02:42:07 +0000 | [diff] [blame] | 51 |  | 
 | 52 | \begin{funcdesc}{ErrorString}{errno} | 
 | 53 | Returns an explanatory string for a given error number \var{errno}. | 
 | 54 | \end{funcdesc} | 
 | 55 |  | 
| Fred Drake | efffe8e | 2000-10-29 05:10:30 +0000 | [diff] [blame] | 56 | \begin{funcdesc}{ParserCreate}{\optional{encoding\optional{, | 
 | 57 |                                namespace_separator}}} | 
| Andrew M. Kuchling | 6b14eeb | 2000-06-11 02:42:07 +0000 | [diff] [blame] | 58 | Creates and returns a new \class{xmlparser} object.   | 
 | 59 | \var{encoding}, if specified, must be a string naming the encoding  | 
 | 60 | used by the XML data.  Expat doesn't support as many encodings as | 
 | 61 | Python does, and its repertoire of encodings can't be extended; it | 
| Fred Drake | 5ed1dac | 2001-02-08 15:40:33 +0000 | [diff] [blame] | 62 | supports UTF-8, UTF-16, ISO-8859-1 (Latin1), and ASCII.  If | 
 | 63 | \var{encoding} is given it will override the implicit or explicit | 
 | 64 | encoding of the document. | 
| Andrew M. Kuchling | 6b14eeb | 2000-06-11 02:42:07 +0000 | [diff] [blame] | 65 |  | 
| Andrew M. Kuchling | 6b14eeb | 2000-06-11 02:42:07 +0000 | [diff] [blame] | 66 | Expat can optionally do XML namespace processing for you, enabled by | 
| Fred Drake | efffe8e | 2000-10-29 05:10:30 +0000 | [diff] [blame] | 67 | providing a value for \var{namespace_separator}.  The value must be a | 
 | 68 | one-character string; a \exception{ValueError} will be raised if the | 
 | 69 | string has an illegal length (\code{None} is considered the same as | 
 | 70 | omission).  When namespace processing is enabled, element type names | 
 | 71 | and attribute names that belong to a namespace will be expanded.  The | 
 | 72 | element name passed to the element handlers | 
| Fred Drake | 5ed1dac | 2001-02-08 15:40:33 +0000 | [diff] [blame] | 73 | \member{StartElementHandler} and \member{EndElementHandler} | 
| Andrew M. Kuchling | 6b14eeb | 2000-06-11 02:42:07 +0000 | [diff] [blame] | 74 | will be the concatenation of the namespace URI, the namespace | 
 | 75 | separator character, and the local part of the name.  If the namespace | 
| Fred Drake | efffe8e | 2000-10-29 05:10:30 +0000 | [diff] [blame] | 76 | separator is a zero byte (\code{chr(0)}) then the namespace URI and | 
| Fred Drake | 5ed1dac | 2001-02-08 15:40:33 +0000 | [diff] [blame] | 77 | the local part will be concatenated without any separator. | 
| Andrew M. Kuchling | 6b14eeb | 2000-06-11 02:42:07 +0000 | [diff] [blame] | 78 |  | 
| Fred Drake | 2fef3ab | 2000-11-28 06:38:22 +0000 | [diff] [blame] | 79 | For example, if \var{namespace_separator} is set to a space character | 
 | 80 | (\character{ }) and the following document is parsed: | 
| Andrew M. Kuchling | 6b14eeb | 2000-06-11 02:42:07 +0000 | [diff] [blame] | 81 |  | 
 | 82 | \begin{verbatim} | 
 | 83 | <?xml version="1.0"?> | 
 | 84 | <root xmlns    = "http://default-namespace.org/" | 
 | 85 |       xmlns:py = "http://www.python.org/ns/"> | 
 | 86 |   <py:elem1 /> | 
 | 87 |   <elem2 xmlns="" /> | 
 | 88 | </root> | 
 | 89 | \end{verbatim} | 
 | 90 |  | 
| Fred Drake | 5ed1dac | 2001-02-08 15:40:33 +0000 | [diff] [blame] | 91 | \member{StartElementHandler} will receive the following strings | 
| Fred Drake | d79c33a | 2000-09-25 14:14:30 +0000 | [diff] [blame] | 92 | for each element: | 
| Andrew M. Kuchling | 6b14eeb | 2000-06-11 02:42:07 +0000 | [diff] [blame] | 93 |  | 
 | 94 | \begin{verbatim} | 
 | 95 | http://default-namespace.org/ root | 
 | 96 | http://www.python.org/ns/ elem1 | 
 | 97 | elem2 | 
 | 98 | \end{verbatim} | 
| Andrew M. Kuchling | 6b14eeb | 2000-06-11 02:42:07 +0000 | [diff] [blame] | 99 | \end{funcdesc} | 
 | 100 |  | 
| Fred Drake | f08cbb1 | 2000-12-23 22:19:05 +0000 | [diff] [blame] | 101 |  | 
| Fred Drake | dce695aa | 2002-06-20 21:06:03 +0000 | [diff] [blame] | 102 | \begin{seealso} | 
 | 103 |   \seetitle[http://www.libexpat.org/]{The Expat XML Parser} | 
 | 104 |            {Home page of the Expat project.} | 
 | 105 | \end{seealso} | 
 | 106 |  | 
 | 107 |  | 
| Fred Drake | f08cbb1 | 2000-12-23 22:19:05 +0000 | [diff] [blame] | 108 | \subsection{XMLParser Objects \label{xmlparser-objects}} | 
 | 109 |  | 
| Andrew M. Kuchling | 6b14eeb | 2000-06-11 02:42:07 +0000 | [diff] [blame] | 110 | \class{xmlparser} objects have the following methods: | 
 | 111 |  | 
| Fred Drake | 2fef3ab | 2000-11-28 06:38:22 +0000 | [diff] [blame] | 112 | \begin{methoddesc}[xmlparser]{Parse}{data\optional{, isfinal}} | 
| Andrew M. Kuchling | 6b14eeb | 2000-06-11 02:42:07 +0000 | [diff] [blame] | 113 | Parses the contents of the string \var{data}, calling the appropriate | 
 | 114 | handler functions to process the parsed data.  \var{isfinal} must be | 
| Fred Drake | f08cbb1 | 2000-12-23 22:19:05 +0000 | [diff] [blame] | 115 | true on the final call to this method.  \var{data} can be the empty | 
| Fred Drake | c05cbb0 | 2000-07-05 02:03:34 +0000 | [diff] [blame] | 116 | string at any time. | 
| Andrew M. Kuchling | 6b14eeb | 2000-06-11 02:42:07 +0000 | [diff] [blame] | 117 | \end{methoddesc} | 
 | 118 |  | 
| Fred Drake | efffe8e | 2000-10-29 05:10:30 +0000 | [diff] [blame] | 119 | \begin{methoddesc}[xmlparser]{ParseFile}{file} | 
| Andrew M. Kuchling | 6b14eeb | 2000-06-11 02:42:07 +0000 | [diff] [blame] | 120 | Parse XML data reading from the object \var{file}.  \var{file} only | 
 | 121 | needs to provide the \method{read(\var{nbytes})} method, returning the | 
 | 122 | empty string when there's no more data. | 
 | 123 | \end{methoddesc} | 
 | 124 |  | 
| Fred Drake | efffe8e | 2000-10-29 05:10:30 +0000 | [diff] [blame] | 125 | \begin{methoddesc}[xmlparser]{SetBase}{base} | 
| Fred Drake | 5ed1dac | 2001-02-08 15:40:33 +0000 | [diff] [blame] | 126 | Sets the base to be used for resolving relative URIs in system | 
 | 127 | identifiers in declarations.  Resolving relative identifiers is left | 
 | 128 | to the application: this value will be passed through as the | 
 | 129 | \var{base} argument to the \function{ExternalEntityRefHandler}, | 
 | 130 | \function{NotationDeclHandler}, and | 
 | 131 | \function{UnparsedEntityDeclHandler} functions. | 
| Andrew M. Kuchling | 6b14eeb | 2000-06-11 02:42:07 +0000 | [diff] [blame] | 132 | \end{methoddesc} | 
 | 133 |  | 
| Fred Drake | efffe8e | 2000-10-29 05:10:30 +0000 | [diff] [blame] | 134 | \begin{methoddesc}[xmlparser]{GetBase}{} | 
| Andrew M. Kuchling | 6b14eeb | 2000-06-11 02:42:07 +0000 | [diff] [blame] | 135 | Returns a string containing the base set by a previous call to | 
 | 136 | \method{SetBase()}, or \code{None} if  | 
 | 137 | \method{SetBase()} hasn't been called. | 
 | 138 | \end{methoddesc} | 
 | 139 |  | 
| Fred Drake | 1d8ad2b | 2001-02-14 18:54:32 +0000 | [diff] [blame] | 140 | \begin{methoddesc}[xmlparser]{GetInputContext}{} | 
 | 141 | Returns the input data that generated the current event as a string. | 
 | 142 | The data is in the encoding of the entity which contains the text. | 
 | 143 | When called while an event handler is not active, the return value is | 
 | 144 | \code{None}. | 
 | 145 | \versionadded{2.1} | 
 | 146 | \end{methoddesc} | 
 | 147 |  | 
| Fred Drake | f08cbb1 | 2000-12-23 22:19:05 +0000 | [diff] [blame] | 148 | \begin{methoddesc}[xmlparser]{ExternalEntityParserCreate}{context\optional{, | 
 | 149 |                                                           encoding}} | 
 | 150 | Create a ``child'' parser which can be used to parse an external | 
 | 151 | parsed entity referred to by content parsed by the parent parser.  The | 
| Fred Drake | b162d18 | 2001-01-04 05:48:08 +0000 | [diff] [blame] | 152 | \var{context} parameter should be the string passed to the | 
| Fred Drake | f08cbb1 | 2000-12-23 22:19:05 +0000 | [diff] [blame] | 153 | \method{ExternalEntityRefHandler()} handler function, described below. | 
| Fred Drake | 5ed1dac | 2001-02-08 15:40:33 +0000 | [diff] [blame] | 154 | The child parser is created with the \member{ordered_attributes}, | 
 | 155 | \member{returns_unicode} and \member{specified_attributes} set to the | 
 | 156 | values of this parser. | 
| Fred Drake | f08cbb1 | 2000-12-23 22:19:05 +0000 | [diff] [blame] | 157 | \end{methoddesc} | 
 | 158 |  | 
| Fred Drake | efffe8e | 2000-10-29 05:10:30 +0000 | [diff] [blame] | 159 |  | 
| Fred Drake | d79c33a | 2000-09-25 14:14:30 +0000 | [diff] [blame] | 160 | \class{xmlparser} objects have the following attributes: | 
| Andrew M. Kuchling | 0690c86 | 2000-08-17 23:15:21 +0000 | [diff] [blame] | 161 |  | 
| Fred Drake | f0b095d | 2002-07-17 20:31:52 +0000 | [diff] [blame] | 162 | \begin{memberdesc}[xmlparser]{buffer_size} | 
 | 163 | The size of the buffer used when \member{buffer_text} is true.  This | 
 | 164 | value cannot be changed at this time. | 
 | 165 | \versionadded{2.3} | 
 | 166 | \end{memberdesc} | 
 | 167 |  | 
 | 168 | \begin{memberdesc}[xmlparser]{buffer_text} | 
 | 169 | Setting this to true causes the \class{xmlparser} object to buffer | 
 | 170 | textual content returned by Expat to avoid multiple calls to the | 
 | 171 | \method{CharacterDataHandler()} callback whenever possible.  This can | 
 | 172 | improve performance substantially since Expat normally breaks | 
 | 173 | character data into chunks at every line ending.  This attribute is | 
 | 174 | false by default, and may be changed at any time. | 
 | 175 | \versionadded{2.3} | 
 | 176 | \end{memberdesc} | 
 | 177 |  | 
 | 178 | \begin{memberdesc}[xmlparser]{buffer_used} | 
 | 179 | If \member{buffer_text} is enabled, the number of bytes stored in the | 
 | 180 | buffer.  These bytes represent UTF-8 encoded text.  This attribute has | 
 | 181 | no meaningful interpretation when \member{buffer_text} is false. | 
 | 182 | \versionadded{2.3} | 
 | 183 | \end{memberdesc} | 
 | 184 |  | 
| Fred Drake | 5ed1dac | 2001-02-08 15:40:33 +0000 | [diff] [blame] | 185 | \begin{memberdesc}[xmlparser]{ordered_attributes} | 
 | 186 | Setting this attribute to a non-zero integer causes the attributes to | 
 | 187 | be reported as a list rather than a dictionary.  The attributes are | 
 | 188 | presented in the order found in the document text.  For each | 
 | 189 | attribute, two list entries are presented: the attribute name and the | 
 | 190 | attribute value.  (Older versions of this module also used this | 
 | 191 | format.)  By default, this attribute is false; it may be changed at | 
 | 192 | any time. | 
 | 193 | \versionadded{2.1} | 
 | 194 | \end{memberdesc} | 
 | 195 |  | 
| Fred Drake | efffe8e | 2000-10-29 05:10:30 +0000 | [diff] [blame] | 196 | \begin{memberdesc}[xmlparser]{returns_unicode}  | 
| Fred Drake | 5ed1dac | 2001-02-08 15:40:33 +0000 | [diff] [blame] | 197 | If this attribute is set to a non-zero integer, the handler functions | 
 | 198 | will be passed Unicode strings.  If \member{returns_unicode} is 0, | 
 | 199 | 8-bit strings containing UTF-8 encoded data will be passed to the | 
 | 200 | handlers. | 
| Fred Drake | b62966c | 2000-12-07 00:00:21 +0000 | [diff] [blame] | 201 | \versionchanged[Can be changed at any time to affect the result | 
| Fred Drake | e0af35e | 2001-09-20 20:43:28 +0000 | [diff] [blame] | 202 |   type]{1.6} | 
| Fred Drake | efffe8e | 2000-10-29 05:10:30 +0000 | [diff] [blame] | 203 | \end{memberdesc} | 
| Andrew M. Kuchling | 0690c86 | 2000-08-17 23:15:21 +0000 | [diff] [blame] | 204 |  | 
| Fred Drake | 5ed1dac | 2001-02-08 15:40:33 +0000 | [diff] [blame] | 205 | \begin{memberdesc}[xmlparser]{specified_attributes} | 
 | 206 | If set to a non-zero integer, the parser will report only those | 
 | 207 | attributes which were specified in the document instance and not those | 
 | 208 | which were derived from attribute declarations.  Applications which | 
 | 209 | set this need to be especially careful to use what additional | 
 | 210 | information is available from the declarations as needed to comply | 
 | 211 | with the standards for the behavior of XML processors.  By default, | 
 | 212 | this attribute is false; it may be changed at any time. | 
 | 213 | \versionadded{2.1} | 
 | 214 | \end{memberdesc} | 
 | 215 |  | 
| Andrew M. Kuchling | 0690c86 | 2000-08-17 23:15:21 +0000 | [diff] [blame] | 216 | The following attributes contain values relating to the most recent | 
 | 217 | error encountered by an \class{xmlparser} object, and will only have | 
 | 218 | correct values once a call to \method{Parse()} or \method{ParseFile()} | 
| Fred Drake | 523ec57 | 2001-02-15 05:37:51 +0000 | [diff] [blame] | 219 | has raised a \exception{xml.parsers.expat.ExpatError} exception. | 
| Andrew M. Kuchling | 6b14eeb | 2000-06-11 02:42:07 +0000 | [diff] [blame] | 220 |  | 
| Fred Drake | efffe8e | 2000-10-29 05:10:30 +0000 | [diff] [blame] | 221 | \begin{memberdesc}[xmlparser]{ErrorByteIndex}  | 
| Andrew M. Kuchling | 6b14eeb | 2000-06-11 02:42:07 +0000 | [diff] [blame] | 222 | Byte index at which an error occurred. | 
| Fred Drake | efffe8e | 2000-10-29 05:10:30 +0000 | [diff] [blame] | 223 | \end{memberdesc}  | 
| Andrew M. Kuchling | 6b14eeb | 2000-06-11 02:42:07 +0000 | [diff] [blame] | 224 |  | 
| Fred Drake | efffe8e | 2000-10-29 05:10:30 +0000 | [diff] [blame] | 225 | \begin{memberdesc}[xmlparser]{ErrorCode}  | 
| Andrew M. Kuchling | 6b14eeb | 2000-06-11 02:42:07 +0000 | [diff] [blame] | 226 | Numeric code specifying the problem.  This value can be passed to the | 
 | 227 | \function{ErrorString()} function, or compared to one of the constants | 
| Fred Drake | 523ec57 | 2001-02-15 05:37:51 +0000 | [diff] [blame] | 228 | defined in the \code{errors} object. | 
| Fred Drake | efffe8e | 2000-10-29 05:10:30 +0000 | [diff] [blame] | 229 | \end{memberdesc} | 
| Andrew M. Kuchling | 6b14eeb | 2000-06-11 02:42:07 +0000 | [diff] [blame] | 230 |  | 
| Fred Drake | efffe8e | 2000-10-29 05:10:30 +0000 | [diff] [blame] | 231 | \begin{memberdesc}[xmlparser]{ErrorColumnNumber}  | 
| Andrew M. Kuchling | 6b14eeb | 2000-06-11 02:42:07 +0000 | [diff] [blame] | 232 | Column number at which an error occurred. | 
| Fred Drake | efffe8e | 2000-10-29 05:10:30 +0000 | [diff] [blame] | 233 | \end{memberdesc} | 
| Andrew M. Kuchling | 6b14eeb | 2000-06-11 02:42:07 +0000 | [diff] [blame] | 234 |  | 
| Fred Drake | efffe8e | 2000-10-29 05:10:30 +0000 | [diff] [blame] | 235 | \begin{memberdesc}[xmlparser]{ErrorLineNumber} | 
| Andrew M. Kuchling | 6b14eeb | 2000-06-11 02:42:07 +0000 | [diff] [blame] | 236 | Line number at which an error occurred. | 
| Fred Drake | efffe8e | 2000-10-29 05:10:30 +0000 | [diff] [blame] | 237 | \end{memberdesc} | 
| Andrew M. Kuchling | 6b14eeb | 2000-06-11 02:42:07 +0000 | [diff] [blame] | 238 |  | 
 | 239 | Here is the list of handlers that can be set.  To set a handler on an | 
| Fred Drake | c05cbb0 | 2000-07-05 02:03:34 +0000 | [diff] [blame] | 240 | \class{xmlparser} object \var{o}, use | 
 | 241 | \code{\var{o}.\var{handlername} = \var{func}}.  \var{handlername} must | 
 | 242 | be taken from the following list, and \var{func} must be a callable | 
 | 243 | object accepting the correct number of arguments.  The arguments are | 
 | 244 | all strings, unless otherwise stated. | 
| Andrew M. Kuchling | 6b14eeb | 2000-06-11 02:42:07 +0000 | [diff] [blame] | 245 |  | 
| Fred Drake | 5ed1dac | 2001-02-08 15:40:33 +0000 | [diff] [blame] | 246 | \begin{methoddesc}[xmlparser]{XmlDeclHandler}{version, encoding, standalone} | 
 | 247 | Called when the XML declaration is parsed.  The XML declaration is the | 
 | 248 | (optional) declaration of the applicable version of the XML | 
 | 249 | recommendation, the encoding of the document text, and an optional | 
 | 250 | ``standalone'' declaration.  \var{version} and \var{encoding} will be | 
 | 251 | strings of the type dictated by the \member{returns_unicode} | 
 | 252 | attribute, and \var{standalone} will be \code{1} if the document is | 
 | 253 | declared standalone, \code{0} if it is declared not to be standalone, | 
 | 254 | or \code{-1} if the standalone clause was omitted. | 
 | 255 | This is only available with Expat version 1.95.0 or newer. | 
 | 256 | \versionadded{2.1} | 
 | 257 | \end{methoddesc} | 
 | 258 |  | 
 | 259 | \begin{methoddesc}[xmlparser]{StartDoctypeDeclHandler}{doctypeName, | 
 | 260 |                                                        systemId, publicId, | 
 | 261 |                                                        has_internal_subset} | 
 | 262 | Called when Expat begins parsing the document type declaration | 
 | 263 | (\code{<!DOCTYPE \ldots}).  The \var{doctypeName} is provided exactly | 
 | 264 | as presented.  The \var{systemId} and \var{publicId} parameters give | 
 | 265 | the system and public identifiers if specified, or \code{None} if | 
 | 266 | omitted.  \var{has_internal_subset} will be true if the document | 
 | 267 | contains and internal document declaration subset. | 
 | 268 | This requires Expat version 1.2 or newer. | 
 | 269 | \end{methoddesc} | 
 | 270 |  | 
 | 271 | \begin{methoddesc}[xmlparser]{EndDoctypeDeclHandler}{} | 
 | 272 | Called when Expat is done parsing the document type delaration. | 
 | 273 | This requires Expat version 1.2 or newer. | 
 | 274 | \end{methoddesc} | 
 | 275 |  | 
 | 276 | \begin{methoddesc}[xmlparser]{ElementDeclHandler}{name, model} | 
 | 277 | Called once for each element type declaration.  \var{name} is the name | 
 | 278 | of the element type, and \var{model} is a representation of the | 
 | 279 | content model. | 
 | 280 | \end{methoddesc} | 
 | 281 |  | 
 | 282 | \begin{methoddesc}[xmlparser]{AttlistDeclHandler}{elname, attname, | 
 | 283 |                                                   type, default, required} | 
 | 284 | Called for each declared attribute for an element type.  If an | 
 | 285 | attribute list declaration declares three attributes, this handler is | 
 | 286 | called three times, once for each attribute.  \var{elname} is the name | 
 | 287 | of the element to which the declaration applies and \var{attname} is | 
 | 288 | the name of the attribute declared.  The attribute type is a string | 
 | 289 | passed as \var{type}; the possible values are \code{'CDATA'}, | 
 | 290 | \code{'ID'}, \code{'IDREF'}, ... | 
 | 291 | \var{default} gives the default value for the attribute used when the | 
 | 292 | attribute is not specified by the document instance, or \code{None} if | 
 | 293 | there is no default value (\code{\#IMPLIED} values).  If the attribute | 
 | 294 | is required to be given in the document instance, \var{required} will | 
 | 295 | be true. | 
 | 296 | This requires Expat version 1.95.0 or newer. | 
 | 297 | \end{methoddesc} | 
 | 298 |  | 
| Fred Drake | efffe8e | 2000-10-29 05:10:30 +0000 | [diff] [blame] | 299 | \begin{methoddesc}[xmlparser]{StartElementHandler}{name, attributes} | 
| Andrew M. Kuchling | 6b14eeb | 2000-06-11 02:42:07 +0000 | [diff] [blame] | 300 | Called for the start of every element.  \var{name} is a string | 
 | 301 | containing the element name, and \var{attributes} is a dictionary | 
 | 302 | mapping attribute names to their values. | 
 | 303 | \end{methoddesc} | 
 | 304 |  | 
| Fred Drake | efffe8e | 2000-10-29 05:10:30 +0000 | [diff] [blame] | 305 | \begin{methoddesc}[xmlparser]{EndElementHandler}{name} | 
| Andrew M. Kuchling | 6b14eeb | 2000-06-11 02:42:07 +0000 | [diff] [blame] | 306 | Called for the end of every element. | 
 | 307 | \end{methoddesc} | 
 | 308 |  | 
| Fred Drake | efffe8e | 2000-10-29 05:10:30 +0000 | [diff] [blame] | 309 | \begin{methoddesc}[xmlparser]{ProcessingInstructionHandler}{target, data} | 
| Fred Drake | 5ed1dac | 2001-02-08 15:40:33 +0000 | [diff] [blame] | 310 | Called for every processing instruction. | 
| Andrew M. Kuchling | 6b14eeb | 2000-06-11 02:42:07 +0000 | [diff] [blame] | 311 | \end{methoddesc} | 
 | 312 |  | 
| Fred Drake | efffe8e | 2000-10-29 05:10:30 +0000 | [diff] [blame] | 313 | \begin{methoddesc}[xmlparser]{CharacterDataHandler}{data} | 
| Fred Drake | 5ed1dac | 2001-02-08 15:40:33 +0000 | [diff] [blame] | 314 | Called for character data.  This will be called for normal character | 
 | 315 | data, CDATA marked content, and ignorable whitespace.  Applications | 
 | 316 | which must distinguish these cases can use the | 
 | 317 | \member{StartCdataSectionHandler}, \member{EndCdataSectionHandler}, | 
 | 318 | and \member{ElementDeclHandler} callbacks to collect the required | 
 | 319 | information. | 
| Andrew M. Kuchling | 6b14eeb | 2000-06-11 02:42:07 +0000 | [diff] [blame] | 320 | \end{methoddesc} | 
 | 321 |  | 
| Fred Drake | efffe8e | 2000-10-29 05:10:30 +0000 | [diff] [blame] | 322 | \begin{methoddesc}[xmlparser]{UnparsedEntityDeclHandler}{entityName, base, | 
 | 323 |                                                          systemId, publicId, | 
 | 324 |                                                          notationName} | 
| Fred Drake | 5ed1dac | 2001-02-08 15:40:33 +0000 | [diff] [blame] | 325 | Called for unparsed (NDATA) entity declarations.  This is only present | 
 | 326 | for version 1.2 of the Expat library; for more recent versions, use | 
 | 327 | \member{EntityDeclHandler} instead.  (The underlying function in the | 
 | 328 | Expat library has been declared obsolete.) | 
 | 329 | \end{methoddesc} | 
 | 330 |  | 
 | 331 | \begin{methoddesc}[xmlparser]{EntityDeclHandler}{entityName, | 
 | 332 |                                                  is_parameter_entity, value, | 
 | 333 |                                                  base, systemId, | 
 | 334 |                                                  publicId, | 
 | 335 |                                                  notationName} | 
 | 336 | Called for all entity declarations.  For parameter and internal | 
 | 337 | entities, \var{value} will be a string giving the declared contents | 
 | 338 | of the entity; this will be \code{None} for external entities.  The | 
 | 339 | \var{notationName} parameter will be \code{None} for parsed entities, | 
 | 340 | and the name of the notation for unparsed entities. | 
 | 341 | \var{is_parameter_entity} will be true if the entity is a paremeter | 
 | 342 | entity or false for general entities (most applications only need to | 
 | 343 | be concerned with general entities). | 
 | 344 | This is only available starting with version 1.95.0 of the Expat | 
 | 345 | library. | 
 | 346 | \versionadded{2.1} | 
| Andrew M. Kuchling | 6b14eeb | 2000-06-11 02:42:07 +0000 | [diff] [blame] | 347 | \end{methoddesc} | 
 | 348 |  | 
| Fred Drake | efffe8e | 2000-10-29 05:10:30 +0000 | [diff] [blame] | 349 | \begin{methoddesc}[xmlparser]{NotationDeclHandler}{notationName, base, | 
 | 350 |                                                    systemId, publicId} | 
| Fred Drake | 5ed1dac | 2001-02-08 15:40:33 +0000 | [diff] [blame] | 351 | Called for notation declarations.  \var{notationName}, \var{base}, and | 
 | 352 | \var{systemId}, and \var{publicId} are strings if given.  If the | 
 | 353 | public identifier is omitted, \var{publicId} will be \code{None}. | 
| Andrew M. Kuchling | 6b14eeb | 2000-06-11 02:42:07 +0000 | [diff] [blame] | 354 | \end{methoddesc} | 
 | 355 |  | 
| Fred Drake | efffe8e | 2000-10-29 05:10:30 +0000 | [diff] [blame] | 356 | \begin{methoddesc}[xmlparser]{StartNamespaceDeclHandler}{prefix, uri} | 
| Fred Drake | 5ed1dac | 2001-02-08 15:40:33 +0000 | [diff] [blame] | 357 | Called when an element contains a namespace declaration.  Namespace | 
 | 358 | declarations are processed before the \member{StartElementHandler} is | 
 | 359 | called for the element on which declarations are placed. | 
| Andrew M. Kuchling | 6b14eeb | 2000-06-11 02:42:07 +0000 | [diff] [blame] | 360 | \end{methoddesc} | 
 | 361 |  | 
| Fred Drake | efffe8e | 2000-10-29 05:10:30 +0000 | [diff] [blame] | 362 | \begin{methoddesc}[xmlparser]{EndNamespaceDeclHandler}{prefix} | 
| Andrew M. Kuchling | 6b14eeb | 2000-06-11 02:42:07 +0000 | [diff] [blame] | 363 | Called when the closing tag is reached for an element  | 
| Fred Drake | 5ed1dac | 2001-02-08 15:40:33 +0000 | [diff] [blame] | 364 | that contained a namespace declaration.  This is called once for each | 
 | 365 | namespace declaration on the element in the reverse of the order for | 
 | 366 | which the \member{StartNamespaceDeclHandler} was called to indicate | 
 | 367 | the start of each namespace declaration's scope.  Calls to this | 
 | 368 | handler are made after the corresponding \member{EndElementHandler} | 
 | 369 | for the end of the element. | 
| Andrew M. Kuchling | 6b14eeb | 2000-06-11 02:42:07 +0000 | [diff] [blame] | 370 | \end{methoddesc} | 
 | 371 |  | 
| Fred Drake | efffe8e | 2000-10-29 05:10:30 +0000 | [diff] [blame] | 372 | \begin{methoddesc}[xmlparser]{CommentHandler}{data} | 
| Fred Drake | 5ed1dac | 2001-02-08 15:40:33 +0000 | [diff] [blame] | 373 | Called for comments.  \var{data} is the text of the comment, excluding | 
| Fred Drake | 523ec57 | 2001-02-15 05:37:51 +0000 | [diff] [blame] | 374 | the leading `\code{<!-}\code{-}' and trailing `\code{-}\code{->}'. | 
| Andrew M. Kuchling | 6b14eeb | 2000-06-11 02:42:07 +0000 | [diff] [blame] | 375 | \end{methoddesc} | 
 | 376 |  | 
| Fred Drake | efffe8e | 2000-10-29 05:10:30 +0000 | [diff] [blame] | 377 | \begin{methoddesc}[xmlparser]{StartCdataSectionHandler}{} | 
| Fred Drake | 5ed1dac | 2001-02-08 15:40:33 +0000 | [diff] [blame] | 378 | Called at the start of a CDATA section.  This and | 
 | 379 | \member{StartCdataSectionHandler} are needed to be able to identify | 
 | 380 | the syntactical start and end for CDATA sections. | 
| Andrew M. Kuchling | 6b14eeb | 2000-06-11 02:42:07 +0000 | [diff] [blame] | 381 | \end{methoddesc} | 
 | 382 |  | 
| Fred Drake | efffe8e | 2000-10-29 05:10:30 +0000 | [diff] [blame] | 383 | \begin{methoddesc}[xmlparser]{EndCdataSectionHandler}{} | 
| Andrew M. Kuchling | 6b14eeb | 2000-06-11 02:42:07 +0000 | [diff] [blame] | 384 | Called at the end of a CDATA section. | 
 | 385 | \end{methoddesc} | 
 | 386 |  | 
| Fred Drake | efffe8e | 2000-10-29 05:10:30 +0000 | [diff] [blame] | 387 | \begin{methoddesc}[xmlparser]{DefaultHandler}{data} | 
| Andrew M. Kuchling | 6b14eeb | 2000-06-11 02:42:07 +0000 | [diff] [blame] | 388 | Called for any characters in the XML document for | 
 | 389 | which no applicable handler has been specified.  This means | 
 | 390 | characters that are part of a construct which could be reported, but | 
 | 391 | for which no handler has been supplied.  | 
 | 392 | \end{methoddesc} | 
 | 393 |  | 
| Fred Drake | efffe8e | 2000-10-29 05:10:30 +0000 | [diff] [blame] | 394 | \begin{methoddesc}[xmlparser]{DefaultHandlerExpand}{data} | 
| Andrew M. Kuchling | 6b14eeb | 2000-06-11 02:42:07 +0000 | [diff] [blame] | 395 | This is the same as the \function{DefaultHandler},  | 
 | 396 | but doesn't inhibit expansion of internal entities. | 
 | 397 | The entity reference will not be passed to the default handler. | 
 | 398 | \end{methoddesc} | 
 | 399 |  | 
| Fred Drake | 5ed1dac | 2001-02-08 15:40:33 +0000 | [diff] [blame] | 400 | \begin{methoddesc}[xmlparser]{NotStandaloneHandler}{} Called if the | 
 | 401 | XML document hasn't been declared as being a standalone document. | 
 | 402 | This happens when there is an external subset or a reference to a | 
 | 403 | parameter entity, but the XML declaration does not set standalone to | 
 | 404 | \code{yes} in an XML declaration.  If this handler returns \code{0}, | 
 | 405 | then the parser will throw an \constant{XML_ERROR_NOT_STANDALONE} | 
 | 406 | error.  If this handler is not set, no exception is raised by the | 
 | 407 | parser for this condition. | 
| Andrew M. Kuchling | 6b14eeb | 2000-06-11 02:42:07 +0000 | [diff] [blame] | 408 | \end{methoddesc} | 
 | 409 |  | 
| Fred Drake | efffe8e | 2000-10-29 05:10:30 +0000 | [diff] [blame] | 410 | \begin{methoddesc}[xmlparser]{ExternalEntityRefHandler}{context, base, | 
 | 411 |                                                         systemId, publicId} | 
| Fred Drake | 5ed1dac | 2001-02-08 15:40:33 +0000 | [diff] [blame] | 412 | Called for references to external entities.  \var{base} is the current | 
 | 413 | base, as set by a previous call to \method{SetBase()}.  The public and | 
 | 414 | system identifiers, \var{systemId} and \var{publicId}, are strings if | 
 | 415 | given; if the public identifier is not given, \var{publicId} will be | 
| Fred Drake | 523ec57 | 2001-02-15 05:37:51 +0000 | [diff] [blame] | 416 | \code{None}.  The \var{context} value is opaque and should only be | 
 | 417 | used as described below. | 
| Fred Drake | 5ed1dac | 2001-02-08 15:40:33 +0000 | [diff] [blame] | 418 |  | 
 | 419 | For external entities to be parsed, this handler must be implemented. | 
 | 420 | It is responsible for creating the sub-parser using | 
| Fred Drake | 523ec57 | 2001-02-15 05:37:51 +0000 | [diff] [blame] | 421 | \code{ExternalEntityParserCreate(\var{context})}, initializing it with | 
 | 422 | the appropriate callbacks, and parsing the entity.  This handler | 
 | 423 | should return an integer; if it returns \code{0}, the parser will | 
 | 424 | throw an \constant{XML_ERROR_EXTERNAL_ENTITY_HANDLING} error, | 
 | 425 | otherwise parsing will continue. | 
| Fred Drake | 5ed1dac | 2001-02-08 15:40:33 +0000 | [diff] [blame] | 426 |  | 
 | 427 | If this handler is not provided, external entities are reported by the | 
 | 428 | \member{DefaultHandler} callback, if provided. | 
| Andrew M. Kuchling | 6b14eeb | 2000-06-11 02:42:07 +0000 | [diff] [blame] | 429 | \end{methoddesc} | 
 | 430 |  | 
 | 431 |  | 
| Fred Drake | 1d8ad2b | 2001-02-14 18:54:32 +0000 | [diff] [blame] | 432 | \subsection{ExpatError Exceptions \label{expaterror-objects}} | 
 | 433 | \sectionauthor{Fred L. Drake, Jr.}{fdrake@acm.org} | 
 | 434 |  | 
 | 435 | \exception{ExpatError} exceptions have a number of interesting | 
 | 436 | attributes: | 
 | 437 |  | 
 | 438 | \begin{memberdesc}[ExpatError]{code} | 
 | 439 |   Expat's internal error number for the specific error.  This will | 
 | 440 |   match one of the constants defined in the \code{errors} object from | 
 | 441 |   this module. | 
 | 442 |   \versionadded{2.1} | 
 | 443 | \end{memberdesc} | 
 | 444 |  | 
 | 445 | \begin{memberdesc}[ExpatError]{lineno} | 
 | 446 |   Line number on which the error was detected.  The first line is | 
 | 447 |   numbered \code{1}. | 
 | 448 |   \versionadded{2.1} | 
 | 449 | \end{memberdesc} | 
 | 450 |  | 
 | 451 | \begin{memberdesc}[ExpatError]{offset} | 
 | 452 |   Character offset into the line where the error occurred.  The first | 
 | 453 |   column is numbered \code{0}. | 
 | 454 |   \versionadded{2.1} | 
 | 455 | \end{memberdesc} | 
 | 456 |  | 
 | 457 |  | 
| Fred Drake | 7fbc85c | 2000-09-23 04:47:56 +0000 | [diff] [blame] | 458 | \subsection{Example \label{expat-example}} | 
| Andrew M. Kuchling | 6b14eeb | 2000-06-11 02:42:07 +0000 | [diff] [blame] | 459 |  | 
| Fred Drake | c05cbb0 | 2000-07-05 02:03:34 +0000 | [diff] [blame] | 460 | The following program defines three handlers that just print out their | 
| Andrew M. Kuchling | 6b14eeb | 2000-06-11 02:42:07 +0000 | [diff] [blame] | 461 | arguments. | 
 | 462 |  | 
 | 463 | \begin{verbatim} | 
| Fred Drake | 7fbc85c | 2000-09-23 04:47:56 +0000 | [diff] [blame] | 464 | import xml.parsers.expat | 
| Andrew M. Kuchling | 6b14eeb | 2000-06-11 02:42:07 +0000 | [diff] [blame] | 465 |  | 
 | 466 | # 3 handler functions | 
 | 467 | def start_element(name, attrs): | 
 | 468 |     print 'Start element:', name, attrs | 
 | 469 | def end_element(name): | 
 | 470 |     print 'End element:', name | 
 | 471 | def char_data(data): | 
 | 472 |     print 'Character data:', repr(data) | 
 | 473 |  | 
| Fred Drake | 7fbc85c | 2000-09-23 04:47:56 +0000 | [diff] [blame] | 474 | p = xml.parsers.expat.ParserCreate() | 
| Andrew M. Kuchling | 6b14eeb | 2000-06-11 02:42:07 +0000 | [diff] [blame] | 475 |  | 
 | 476 | p.StartElementHandler = start_element | 
| Fred Drake | 7fbc85c | 2000-09-23 04:47:56 +0000 | [diff] [blame] | 477 | p.EndElementHandler = end_element | 
 | 478 | p.CharacterDataHandler = char_data | 
| Andrew M. Kuchling | 6b14eeb | 2000-06-11 02:42:07 +0000 | [diff] [blame] | 479 |  | 
 | 480 | p.Parse("""<?xml version="1.0"?> | 
 | 481 | <parent id="top"><child1 name="paul">Text goes here</child1> | 
 | 482 | <child2 name="fred">More text</child2> | 
 | 483 | </parent>""") | 
 | 484 | \end{verbatim} | 
 | 485 |  | 
 | 486 | The output from this program is: | 
 | 487 |  | 
 | 488 | \begin{verbatim} | 
 | 489 | Start element: parent {'id': 'top'} | 
 | 490 | Start element: child1 {'name': 'paul'} | 
 | 491 | Character data: 'Text goes here' | 
 | 492 | End element: child1 | 
| Ka-Ping Yee | fa004ad | 2001-01-24 17:19:08 +0000 | [diff] [blame] | 493 | Character data: '\n' | 
| Andrew M. Kuchling | 6b14eeb | 2000-06-11 02:42:07 +0000 | [diff] [blame] | 494 | Start element: child2 {'name': 'fred'} | 
 | 495 | Character data: 'More text' | 
 | 496 | End element: child2 | 
| Ka-Ping Yee | fa004ad | 2001-01-24 17:19:08 +0000 | [diff] [blame] | 497 | Character data: '\n' | 
| Andrew M. Kuchling | 6b14eeb | 2000-06-11 02:42:07 +0000 | [diff] [blame] | 498 | End element: parent | 
 | 499 | \end{verbatim} | 
| Fred Drake | c05cbb0 | 2000-07-05 02:03:34 +0000 | [diff] [blame] | 500 |  | 
 | 501 |  | 
| Fred Drake | 5ed1dac | 2001-02-08 15:40:33 +0000 | [diff] [blame] | 502 | \subsection{Content Model Descriptions \label{expat-content-models}} | 
 | 503 | \sectionauthor{Fred L. Drake, Jr.}{fdrake@acm.org} | 
 | 504 |  | 
 | 505 | Content modules are described using nested tuples.  Each tuple | 
 | 506 | contains four values: the type, the quantifier, the name, and a tuple | 
 | 507 | of children.  Children are simply additional content module | 
 | 508 | descriptions. | 
 | 509 |  | 
 | 510 | The values of the first two fields are constants defined in the | 
 | 511 | \code{model} object of the \module{xml.parsers.expat} module.  These | 
 | 512 | constants can be collected in two groups: the model type group and the | 
 | 513 | quantifier group. | 
 | 514 |  | 
 | 515 | The constants in the model type group are: | 
 | 516 |  | 
 | 517 | \begin{datadescni}{XML_CTYPE_ANY} | 
 | 518 | The element named by the model name was declared to have a content | 
 | 519 | model of \code{ANY}. | 
 | 520 | \end{datadescni} | 
 | 521 |  | 
 | 522 | \begin{datadescni}{XML_CTYPE_CHOICE} | 
 | 523 | The named element allows a choice from a number of options; this is | 
 | 524 | used for content models such as \code{(A | B | C)}. | 
 | 525 | \end{datadescni} | 
 | 526 |  | 
 | 527 | \begin{datadescni}{XML_CTYPE_EMPTY} | 
 | 528 | Elements which are declared to be \code{EMPTY} have this model type. | 
 | 529 | \end{datadescni} | 
 | 530 |  | 
 | 531 | \begin{datadescni}{XML_CTYPE_MIXED} | 
 | 532 | \end{datadescni} | 
 | 533 |  | 
 | 534 | \begin{datadescni}{XML_CTYPE_NAME} | 
 | 535 | \end{datadescni} | 
 | 536 |  | 
 | 537 | \begin{datadescni}{XML_CTYPE_SEQ} | 
 | 538 | Models which represent a series of models which follow one after the | 
 | 539 | other are indicated with this model type.  This is used for models | 
 | 540 | such as \code{(A, B, C)}. | 
 | 541 | \end{datadescni} | 
 | 542 |  | 
 | 543 |  | 
 | 544 | The constants in the quantifier group are: | 
 | 545 |  | 
 | 546 | \begin{datadescni}{XML_CQUANT_NONE} | 
| Fred Drake | e0af35e | 2001-09-20 20:43:28 +0000 | [diff] [blame] | 547 | No modifier is given, so it can appear exactly once, as for \code{A}. | 
| Fred Drake | 5ed1dac | 2001-02-08 15:40:33 +0000 | [diff] [blame] | 548 | \end{datadescni} | 
 | 549 |  | 
 | 550 | \begin{datadescni}{XML_CQUANT_OPT} | 
| Fred Drake | e0af35e | 2001-09-20 20:43:28 +0000 | [diff] [blame] | 551 | The model is optional: it can appear once or not at all, as for | 
| Fred Drake | 5ed1dac | 2001-02-08 15:40:33 +0000 | [diff] [blame] | 552 | \code{A?}. | 
 | 553 | \end{datadescni} | 
 | 554 |  | 
 | 555 | \begin{datadescni}{XML_CQUANT_PLUS} | 
| Fred Drake | e0af35e | 2001-09-20 20:43:28 +0000 | [diff] [blame] | 556 | The model must occur one or more times (like \code{A+}). | 
| Fred Drake | 5ed1dac | 2001-02-08 15:40:33 +0000 | [diff] [blame] | 557 | \end{datadescni} | 
 | 558 |  | 
 | 559 | \begin{datadescni}{XML_CQUANT_REP} | 
 | 560 | The model must occur zero or more times, as for \code{A*}. | 
 | 561 | \end{datadescni} | 
 | 562 |  | 
 | 563 |  | 
| Fred Drake | 7fbc85c | 2000-09-23 04:47:56 +0000 | [diff] [blame] | 564 | \subsection{Expat error constants \label{expat-errors}} | 
| Fred Drake | c05cbb0 | 2000-07-05 02:03:34 +0000 | [diff] [blame] | 565 |  | 
| Fred Drake | 1d8ad2b | 2001-02-14 18:54:32 +0000 | [diff] [blame] | 566 | The following constants are provided in the \code{errors} object of | 
 | 567 | the \refmodule{xml.parsers.expat} module.  These constants are useful | 
 | 568 | in interpreting some of the attributes of the \exception{ExpatError} | 
 | 569 | exception objects raised when an error has occurred. | 
| Fred Drake | c05cbb0 | 2000-07-05 02:03:34 +0000 | [diff] [blame] | 570 |  | 
| Fred Drake | 7fbc85c | 2000-09-23 04:47:56 +0000 | [diff] [blame] | 571 | The \code{errors} object has the following attributes: | 
| Fred Drake | c05cbb0 | 2000-07-05 02:03:34 +0000 | [diff] [blame] | 572 |  | 
| Fred Drake | 5ed1dac | 2001-02-08 15:40:33 +0000 | [diff] [blame] | 573 | \begin{datadescni}{XML_ERROR_ASYNC_ENTITY} | 
 | 574 | \end{datadescni} | 
| Fred Drake | acab3d6 | 2000-07-11 16:30:30 +0000 | [diff] [blame] | 575 |  | 
| Fred Drake | 5ed1dac | 2001-02-08 15:40:33 +0000 | [diff] [blame] | 576 | \begin{datadescni}{XML_ERROR_ATTRIBUTE_EXTERNAL_ENTITY_REF} | 
 | 577 | An entity reference in an attribute value referred to an external | 
 | 578 | entity instead of an internal entity. | 
 | 579 | \end{datadescni} | 
| Fred Drake | acab3d6 | 2000-07-11 16:30:30 +0000 | [diff] [blame] | 580 |  | 
| Fred Drake | 5ed1dac | 2001-02-08 15:40:33 +0000 | [diff] [blame] | 581 | \begin{datadescni}{XML_ERROR_BAD_CHAR_REF} | 
| Fred Drake | e0af35e | 2001-09-20 20:43:28 +0000 | [diff] [blame] | 582 | A character reference referred to a character which is illegal in XML | 
 | 583 | (for example, character \code{0}, or `\code{\&\#0;}'. | 
| Fred Drake | 5ed1dac | 2001-02-08 15:40:33 +0000 | [diff] [blame] | 584 | \end{datadescni} | 
| Fred Drake | acab3d6 | 2000-07-11 16:30:30 +0000 | [diff] [blame] | 585 |  | 
| Fred Drake | 5ed1dac | 2001-02-08 15:40:33 +0000 | [diff] [blame] | 586 | \begin{datadescni}{XML_ERROR_BINARY_ENTITY_REF} | 
| Fred Drake | e0af35e | 2001-09-20 20:43:28 +0000 | [diff] [blame] | 587 | An entity reference referred to an entity which was declared with a | 
 | 588 | notation, so cannot be parsed. | 
| Fred Drake | 5ed1dac | 2001-02-08 15:40:33 +0000 | [diff] [blame] | 589 | \end{datadescni} | 
| Fred Drake | acab3d6 | 2000-07-11 16:30:30 +0000 | [diff] [blame] | 590 |  | 
| Fred Drake | 5ed1dac | 2001-02-08 15:40:33 +0000 | [diff] [blame] | 591 | \begin{datadescni}{XML_ERROR_DUPLICATE_ATTRIBUTE} | 
| Fred Drake | acab3d6 | 2000-07-11 16:30:30 +0000 | [diff] [blame] | 592 | An attribute was used more than once in a start tag. | 
| Fred Drake | 5ed1dac | 2001-02-08 15:40:33 +0000 | [diff] [blame] | 593 | \end{datadescni} | 
| Fred Drake | acab3d6 | 2000-07-11 16:30:30 +0000 | [diff] [blame] | 594 |  | 
| Fred Drake | 5ed1dac | 2001-02-08 15:40:33 +0000 | [diff] [blame] | 595 | \begin{datadescni}{XML_ERROR_INCORRECT_ENCODING} | 
 | 596 | \end{datadescni} | 
| Fred Drake | acab3d6 | 2000-07-11 16:30:30 +0000 | [diff] [blame] | 597 |  | 
| Fred Drake | 5ed1dac | 2001-02-08 15:40:33 +0000 | [diff] [blame] | 598 | \begin{datadescni}{XML_ERROR_INVALID_TOKEN} | 
| Fred Drake | e0af35e | 2001-09-20 20:43:28 +0000 | [diff] [blame] | 599 | Raised when an input byte could not properly be assigned to a | 
 | 600 | character; for example, a NUL byte (value \code{0}) in a UTF-8 input | 
 | 601 | stream. | 
| Fred Drake | 5ed1dac | 2001-02-08 15:40:33 +0000 | [diff] [blame] | 602 | \end{datadescni} | 
| Fred Drake | acab3d6 | 2000-07-11 16:30:30 +0000 | [diff] [blame] | 603 |  | 
| Fred Drake | 5ed1dac | 2001-02-08 15:40:33 +0000 | [diff] [blame] | 604 | \begin{datadescni}{XML_ERROR_JUNK_AFTER_DOC_ELEMENT} | 
| Fred Drake | acab3d6 | 2000-07-11 16:30:30 +0000 | [diff] [blame] | 605 | Something other than whitespace occurred after the document element. | 
| Fred Drake | 5ed1dac | 2001-02-08 15:40:33 +0000 | [diff] [blame] | 606 | \end{datadescni} | 
| Fred Drake | acab3d6 | 2000-07-11 16:30:30 +0000 | [diff] [blame] | 607 |  | 
| Fred Drake | 5ed1dac | 2001-02-08 15:40:33 +0000 | [diff] [blame] | 608 | \begin{datadescni}{XML_ERROR_MISPLACED_XML_PI} | 
| Fred Drake | e0af35e | 2001-09-20 20:43:28 +0000 | [diff] [blame] | 609 | An XML declaration was found somewhere other than the start of the | 
 | 610 | input data. | 
| Fred Drake | 5ed1dac | 2001-02-08 15:40:33 +0000 | [diff] [blame] | 611 | \end{datadescni} | 
| Fred Drake | acab3d6 | 2000-07-11 16:30:30 +0000 | [diff] [blame] | 612 |  | 
| Fred Drake | 5ed1dac | 2001-02-08 15:40:33 +0000 | [diff] [blame] | 613 | \begin{datadescni}{XML_ERROR_NO_ELEMENTS} | 
| Fred Drake | e0af35e | 2001-09-20 20:43:28 +0000 | [diff] [blame] | 614 | The document contains no elements (XML requires all documents to | 
 | 615 | contain exactly one top-level element).. | 
| Fred Drake | 5ed1dac | 2001-02-08 15:40:33 +0000 | [diff] [blame] | 616 | \end{datadescni} | 
| Fred Drake | acab3d6 | 2000-07-11 16:30:30 +0000 | [diff] [blame] | 617 |  | 
| Fred Drake | 5ed1dac | 2001-02-08 15:40:33 +0000 | [diff] [blame] | 618 | \begin{datadescni}{XML_ERROR_NO_MEMORY} | 
| Fred Drake | acab3d6 | 2000-07-11 16:30:30 +0000 | [diff] [blame] | 619 | Expat was not able to allocate memory internally. | 
| Fred Drake | 5ed1dac | 2001-02-08 15:40:33 +0000 | [diff] [blame] | 620 | \end{datadescni} | 
| Fred Drake | acab3d6 | 2000-07-11 16:30:30 +0000 | [diff] [blame] | 621 |  | 
| Fred Drake | 5ed1dac | 2001-02-08 15:40:33 +0000 | [diff] [blame] | 622 | \begin{datadescni}{XML_ERROR_PARAM_ENTITY_REF} | 
| Fred Drake | e0af35e | 2001-09-20 20:43:28 +0000 | [diff] [blame] | 623 | A parameter entity reference was found where it was not allowed. | 
| Fred Drake | 5ed1dac | 2001-02-08 15:40:33 +0000 | [diff] [blame] | 624 | \end{datadescni} | 
| Fred Drake | acab3d6 | 2000-07-11 16:30:30 +0000 | [diff] [blame] | 625 |  | 
| Fred Drake | 5ed1dac | 2001-02-08 15:40:33 +0000 | [diff] [blame] | 626 | \begin{datadescni}{XML_ERROR_PARTIAL_CHAR} | 
| Fred Drake | e0af35e | 2001-09-20 20:43:28 +0000 | [diff] [blame] | 627 |  | 
| Fred Drake | 5ed1dac | 2001-02-08 15:40:33 +0000 | [diff] [blame] | 628 | \end{datadescni} | 
| Fred Drake | acab3d6 | 2000-07-11 16:30:30 +0000 | [diff] [blame] | 629 |  | 
| Fred Drake | 5ed1dac | 2001-02-08 15:40:33 +0000 | [diff] [blame] | 630 | \begin{datadescni}{XML_ERROR_RECURSIVE_ENTITY_REF} | 
| Fred Drake | e0af35e | 2001-09-20 20:43:28 +0000 | [diff] [blame] | 631 | An entity reference contained another reference to the same entity; | 
 | 632 | possibly via a different name, and possibly indirectly. | 
| Fred Drake | 5ed1dac | 2001-02-08 15:40:33 +0000 | [diff] [blame] | 633 | \end{datadescni} | 
| Fred Drake | acab3d6 | 2000-07-11 16:30:30 +0000 | [diff] [blame] | 634 |  | 
| Fred Drake | 5ed1dac | 2001-02-08 15:40:33 +0000 | [diff] [blame] | 635 | \begin{datadescni}{XML_ERROR_SYNTAX} | 
| Fred Drake | acab3d6 | 2000-07-11 16:30:30 +0000 | [diff] [blame] | 636 | Some unspecified syntax error was encountered. | 
| Fred Drake | 5ed1dac | 2001-02-08 15:40:33 +0000 | [diff] [blame] | 637 | \end{datadescni} | 
| Fred Drake | acab3d6 | 2000-07-11 16:30:30 +0000 | [diff] [blame] | 638 |  | 
| Fred Drake | 5ed1dac | 2001-02-08 15:40:33 +0000 | [diff] [blame] | 639 | \begin{datadescni}{XML_ERROR_TAG_MISMATCH} | 
| Fred Drake | acab3d6 | 2000-07-11 16:30:30 +0000 | [diff] [blame] | 640 | An end tag did not match the innermost open start tag. | 
| Fred Drake | 5ed1dac | 2001-02-08 15:40:33 +0000 | [diff] [blame] | 641 | \end{datadescni} | 
| Fred Drake | acab3d6 | 2000-07-11 16:30:30 +0000 | [diff] [blame] | 642 |  | 
| Fred Drake | 5ed1dac | 2001-02-08 15:40:33 +0000 | [diff] [blame] | 643 | \begin{datadescni}{XML_ERROR_UNCLOSED_TOKEN} | 
| Fred Drake | e0af35e | 2001-09-20 20:43:28 +0000 | [diff] [blame] | 644 | Some token (such as a start tag) was not closed before the end of the | 
 | 645 | stream or the next token was encountered. | 
| Fred Drake | 5ed1dac | 2001-02-08 15:40:33 +0000 | [diff] [blame] | 646 | \end{datadescni} | 
| Fred Drake | acab3d6 | 2000-07-11 16:30:30 +0000 | [diff] [blame] | 647 |  | 
| Fred Drake | 5ed1dac | 2001-02-08 15:40:33 +0000 | [diff] [blame] | 648 | \begin{datadescni}{XML_ERROR_UNDEFINED_ENTITY} | 
| Fred Drake | acab3d6 | 2000-07-11 16:30:30 +0000 | [diff] [blame] | 649 | A reference was made to a entity which was not defined. | 
| Fred Drake | 5ed1dac | 2001-02-08 15:40:33 +0000 | [diff] [blame] | 650 | \end{datadescni} | 
| Fred Drake | acab3d6 | 2000-07-11 16:30:30 +0000 | [diff] [blame] | 651 |  | 
| Fred Drake | 5ed1dac | 2001-02-08 15:40:33 +0000 | [diff] [blame] | 652 | \begin{datadescni}{XML_ERROR_UNKNOWN_ENCODING} | 
| Fred Drake | acab3d6 | 2000-07-11 16:30:30 +0000 | [diff] [blame] | 653 | The document encoding is not supported by Expat. | 
| Fred Drake | 5ed1dac | 2001-02-08 15:40:33 +0000 | [diff] [blame] | 654 | \end{datadescni} |