blob: 38ec5c65404b21d24967deee5a62d9d680177169 [file] [log] [blame]
Georg Brandl8ec7f652007-08-15 14:28:01 +00001
2:mod:`xml.parsers.expat` --- Fast XML parsing using Expat
3=========================================================
4
5.. module:: xml.parsers.expat
6 :synopsis: An interface to the Expat non-validating XML parser.
7.. moduleauthor:: Paul Prescod <paul@prescod.net>
8
9
10.. % Markup notes:
11.. %
12.. % Many of the attributes of the XMLParser objects are callbacks.
13.. % Since signature information must be presented, these are described
14.. % using the methoddesc environment. Since they are attributes which
15.. % are set by client code, in-text references to these attributes
16.. % should be marked using the \member macro and should not include the
17.. % parentheses used when marking functions and methods.
18
19.. versionadded:: 2.0
20
21.. index:: single: Expat
22
23The :mod:`xml.parsers.expat` module is a Python interface to the Expat
24non-validating XML parser. The module provides a single extension type,
25:class:`xmlparser`, that represents the current state of an XML parser. After
26an :class:`xmlparser` object has been created, various attributes of the object
27can be set to handler functions. When an XML document is then fed to the
28parser, the handler functions are called for the character data and markup in
29the XML document.
30
31.. index:: module: pyexpat
32
33This module uses the :mod:`pyexpat` module to provide access to the Expat
34parser. Direct use of the :mod:`pyexpat` module is deprecated.
35
36This module provides one exception and one type object:
37
38
39.. exception:: ExpatError
40
41 The exception raised when Expat reports an error. See section
42 :ref:`expaterror-objects` for more information on interpreting Expat errors.
43
44
45.. exception:: error
46
47 Alias for :exc:`ExpatError`.
48
49
50.. data:: XMLParserType
51
52 The type of the return values from the :func:`ParserCreate` function.
53
54The :mod:`xml.parsers.expat` module contains two functions:
55
56
57.. function:: ErrorString(errno)
58
59 Returns an explanatory string for a given error number *errno*.
60
61
62.. function:: ParserCreate([encoding[, namespace_separator]])
63
64 Creates and returns a new :class:`xmlparser` object. *encoding*, if specified,
65 must be a string naming the encoding used by the XML data. Expat doesn't
66 support as many encodings as Python does, and its repertoire of encodings can't
67 be extended; it supports UTF-8, UTF-16, ISO-8859-1 (Latin1), and ASCII. If
68 *encoding* is given it will override the implicit or explicit encoding of the
69 document.
70
71 Expat can optionally do XML namespace processing for you, enabled by providing a
72 value for *namespace_separator*. The value must be a one-character string; a
73 :exc:`ValueError` will be raised if the string has an illegal length (``None``
74 is considered the same as omission). When namespace processing is enabled,
75 element type names and attribute names that belong to a namespace will be
76 expanded. The element name passed to the element handlers
77 :attr:`StartElementHandler` and :attr:`EndElementHandler` will be the
78 concatenation of the namespace URI, the namespace separator character, and the
79 local part of the name. If the namespace separator is a zero byte (``chr(0)``)
80 then the namespace URI and the local part will be concatenated without any
81 separator.
82
83 For example, if *namespace_separator* is set to a space character (``' '``) and
84 the following document is parsed::
85
86 <?xml version="1.0"?>
87 <root xmlns = "http://default-namespace.org/"
88 xmlns:py = "http://www.python.org/ns/">
89 <py:elem1 />
90 <elem2 xmlns="" />
91 </root>
92
93 :attr:`StartElementHandler` will receive the following strings for each
94 element::
95
96 http://default-namespace.org/ root
97 http://www.python.org/ns/ elem1
98 elem2
99
100
101.. seealso::
102
103 `The Expat XML Parser <http://www.libexpat.org/>`_
104 Home page of the Expat project.
105
106
107.. _xmlparser-objects:
108
109XMLParser Objects
110-----------------
111
112:class:`xmlparser` objects have the following methods:
113
114
115.. method:: xmlparser.Parse(data[, isfinal])
116
117 Parses the contents of the string *data*, calling the appropriate handler
118 functions to process the parsed data. *isfinal* must be true on the final call
119 to this method. *data* can be the empty string at any time.
120
121
122.. method:: xmlparser.ParseFile(file)
123
124 Parse XML data reading from the object *file*. *file* only needs to provide
125 the ``read(nbytes)`` method, returning the empty string when there's no more
126 data.
127
128
129.. method:: xmlparser.SetBase(base)
130
131 Sets the base to be used for resolving relative URIs in system identifiers in
132 declarations. Resolving relative identifiers is left to the application: this
133 value will be passed through as the *base* argument to the
134 :func:`ExternalEntityRefHandler`, :func:`NotationDeclHandler`, and
135 :func:`UnparsedEntityDeclHandler` functions.
136
137
138.. method:: xmlparser.GetBase()
139
140 Returns a string containing the base set by a previous call to :meth:`SetBase`,
141 or ``None`` if :meth:`SetBase` hasn't been called.
142
143
144.. method:: xmlparser.GetInputContext()
145
146 Returns the input data that generated the current event as a string. The data is
147 in the encoding of the entity which contains the text. When called while an
148 event handler is not active, the return value is ``None``.
149
150 .. versionadded:: 2.1
151
152
153.. method:: xmlparser.ExternalEntityParserCreate(context[, encoding])
154
155 Create a "child" parser which can be used to parse an external parsed entity
156 referred to by content parsed by the parent parser. The *context* parameter
157 should be the string passed to the :meth:`ExternalEntityRefHandler` handler
158 function, described below. The child parser is created with the
159 :attr:`ordered_attributes`, :attr:`returns_unicode` and
160 :attr:`specified_attributes` set to the values of this parser.
161
162
163.. method:: xmlparser.UseForeignDTD([flag])
164
165 Calling this with a true value for *flag* (the default) will cause Expat to call
166 the :attr:`ExternalEntityRefHandler` with :const:`None` for all arguments to
167 allow an alternate DTD to be loaded. If the document does not contain a
168 document type declaration, the :attr:`ExternalEntityRefHandler` will still be
169 called, but the :attr:`StartDoctypeDeclHandler` and
170 :attr:`EndDoctypeDeclHandler` will not be called.
171
172 Passing a false value for *flag* will cancel a previous call that passed a true
173 value, but otherwise has no effect.
174
175 This method can only be called before the :meth:`Parse` or :meth:`ParseFile`
176 methods are called; calling it after either of those have been called causes
177 :exc:`ExpatError` to be raised with the :attr:`code` attribute set to
178 :const:`errors.XML_ERROR_CANT_CHANGE_FEATURE_ONCE_PARSING`.
179
180 .. versionadded:: 2.3
181
182:class:`xmlparser` objects have the following attributes:
183
184
185.. attribute:: xmlparser.buffer_size
186
187 The size of the buffer used when :attr:`buffer_text` is true. This value cannot
188 be changed at this time.
189
190 .. versionadded:: 2.3
191
192
193.. attribute:: xmlparser.buffer_text
194
195 Setting this to true causes the :class:`xmlparser` object to buffer textual
196 content returned by Expat to avoid multiple calls to the
197 :meth:`CharacterDataHandler` callback whenever possible. This can improve
198 performance substantially since Expat normally breaks character data into chunks
199 at every line ending. This attribute is false by default, and may be changed at
200 any time.
201
202 .. versionadded:: 2.3
203
204
205.. attribute:: xmlparser.buffer_used
206
207 If :attr:`buffer_text` is enabled, the number of bytes stored in the buffer.
208 These bytes represent UTF-8 encoded text. This attribute has no meaningful
209 interpretation when :attr:`buffer_text` is false.
210
211 .. versionadded:: 2.3
212
213
214.. attribute:: xmlparser.ordered_attributes
215
216 Setting this attribute to a non-zero integer causes the attributes to be
217 reported as a list rather than a dictionary. The attributes are presented in
218 the order found in the document text. For each attribute, two list entries are
219 presented: the attribute name and the attribute value. (Older versions of this
220 module also used this format.) By default, this attribute is false; it may be
221 changed at any time.
222
223 .. versionadded:: 2.1
224
225
226.. attribute:: xmlparser.returns_unicode
227
228 If this attribute is set to a non-zero integer, the handler functions will be
229 passed Unicode strings. If :attr:`returns_unicode` is :const:`False`, 8-bit
230 strings containing UTF-8 encoded data will be passed to the handlers. This is
231 :const:`True` by default when Python is built with Unicode support.
232
233 .. versionchanged:: 1.6
234 Can be changed at any time to affect the result type.
235
236
237.. attribute:: xmlparser.specified_attributes
238
239 If set to a non-zero integer, the parser will report only those attributes which
240 were specified in the document instance and not those which were derived from
241 attribute declarations. Applications which set this need to be especially
242 careful to use what additional information is available from the declarations as
243 needed to comply with the standards for the behavior of XML processors. By
244 default, this attribute is false; it may be changed at any time.
245
246 .. versionadded:: 2.1
247
248The following attributes contain values relating to the most recent error
249encountered by an :class:`xmlparser` object, and will only have correct values
250once a call to :meth:`Parse` or :meth:`ParseFile` has raised a
251:exc:`xml.parsers.expat.ExpatError` exception.
252
253
254.. attribute:: xmlparser.ErrorByteIndex
255
256 Byte index at which an error occurred.
257
258
259.. attribute:: xmlparser.ErrorCode
260
261 Numeric code specifying the problem. This value can be passed to the
262 :func:`ErrorString` function, or compared to one of the constants defined in the
263 ``errors`` object.
264
265
266.. attribute:: xmlparser.ErrorColumnNumber
267
268 Column number at which an error occurred.
269
270
271.. attribute:: xmlparser.ErrorLineNumber
272
273 Line number at which an error occurred.
274
275The following attributes contain values relating to the current parse location
276in an :class:`xmlparser` object. During a callback reporting a parse event they
277indicate the location of the first of the sequence of characters that generated
278the event. When called outside of a callback, the position indicated will be
279just past the last parse event (regardless of whether there was an associated
280callback).
281
282.. versionadded:: 2.4
283
284
285.. attribute:: xmlparser.CurrentByteIndex
286
287 Current byte index in the parser input.
288
289
290.. attribute:: xmlparser.CurrentColumnNumber
291
292 Current column number in the parser input.
293
294
295.. attribute:: xmlparser.CurrentLineNumber
296
297 Current line number in the parser input.
298
299Here is the list of handlers that can be set. To set a handler on an
300:class:`xmlparser` object *o*, use ``o.handlername = func``. *handlername* must
301be taken from the following list, and *func* must be a callable object accepting
302the correct number of arguments. The arguments are all strings, unless
303otherwise stated.
304
305
306.. method:: xmlparser.XmlDeclHandler(version, encoding, standalone)
307
308 Called when the XML declaration is parsed. The XML declaration is the
309 (optional) declaration of the applicable version of the XML recommendation, the
310 encoding of the document text, and an optional "standalone" declaration.
311 *version* and *encoding* will be strings of the type dictated by the
312 :attr:`returns_unicode` attribute, and *standalone* will be ``1`` if the
313 document is declared standalone, ``0`` if it is declared not to be standalone,
314 or ``-1`` if the standalone clause was omitted. This is only available with
315 Expat version 1.95.0 or newer.
316
317 .. versionadded:: 2.1
318
319
320.. method:: xmlparser.StartDoctypeDeclHandler(doctypeName, systemId, publicId, has_internal_subset)
321
322 Called when Expat begins parsing the document type declaration (``<!DOCTYPE
323 ...``). The *doctypeName* is provided exactly as presented. The *systemId* and
324 *publicId* parameters give the system and public identifiers if specified, or
325 ``None`` if omitted. *has_internal_subset* will be true if the document
326 contains and internal document declaration subset. This requires Expat version
327 1.2 or newer.
328
329
330.. method:: xmlparser.EndDoctypeDeclHandler()
331
332 Called when Expat is done parsing the document type declaration. This requires
333 Expat version 1.2 or newer.
334
335
336.. method:: xmlparser.ElementDeclHandler(name, model)
337
338 Called once for each element type declaration. *name* is the name of the
339 element type, and *model* is a representation of the content model.
340
341
342.. method:: xmlparser.AttlistDeclHandler(elname, attname, type, default, required)
343
344 Called for each declared attribute for an element type. If an attribute list
345 declaration declares three attributes, this handler is called three times, once
346 for each attribute. *elname* is the name of the element to which the
347 declaration applies and *attname* is the name of the attribute declared. The
348 attribute type is a string passed as *type*; the possible values are
349 ``'CDATA'``, ``'ID'``, ``'IDREF'``, ... *default* gives the default value for
350 the attribute used when the attribute is not specified by the document instance,
351 or ``None`` if there is no default value (``#IMPLIED`` values). If the
352 attribute is required to be given in the document instance, *required* will be
353 true. This requires Expat version 1.95.0 or newer.
354
355
356.. method:: xmlparser.StartElementHandler(name, attributes)
357
358 Called for the start of every element. *name* is a string containing the
359 element name, and *attributes* is a dictionary mapping attribute names to their
360 values.
361
362
363.. method:: xmlparser.EndElementHandler(name)
364
365 Called for the end of every element.
366
367
368.. method:: xmlparser.ProcessingInstructionHandler(target, data)
369
370 Called for every processing instruction.
371
372
373.. method:: xmlparser.CharacterDataHandler(data)
374
375 Called for character data. This will be called for normal character data, CDATA
376 marked content, and ignorable whitespace. Applications which must distinguish
377 these cases can use the :attr:`StartCdataSectionHandler`,
378 :attr:`EndCdataSectionHandler`, and :attr:`ElementDeclHandler` callbacks to
379 collect the required information.
380
381
382.. method:: xmlparser.UnparsedEntityDeclHandler(entityName, base, systemId, publicId, notationName)
383
384 Called for unparsed (NDATA) entity declarations. This is only present for
385 version 1.2 of the Expat library; for more recent versions, use
386 :attr:`EntityDeclHandler` instead. (The underlying function in the Expat
387 library has been declared obsolete.)
388
389
390.. method:: xmlparser.EntityDeclHandler(entityName, is_parameter_entity, value, base, systemId, publicId, notationName)
391
392 Called for all entity declarations. For parameter and internal entities,
393 *value* will be a string giving the declared contents of the entity; this will
394 be ``None`` for external entities. The *notationName* parameter will be
395 ``None`` for parsed entities, and the name of the notation for unparsed
396 entities. *is_parameter_entity* will be true if the entity is a parameter entity
397 or false for general entities (most applications only need to be concerned with
398 general entities). This is only available starting with version 1.95.0 of the
399 Expat library.
400
401 .. versionadded:: 2.1
402
403
404.. method:: xmlparser.NotationDeclHandler(notationName, base, systemId, publicId)
405
406 Called for notation declarations. *notationName*, *base*, and *systemId*, and
407 *publicId* are strings if given. If the public identifier is omitted,
408 *publicId* will be ``None``.
409
410
411.. method:: xmlparser.StartNamespaceDeclHandler(prefix, uri)
412
413 Called when an element contains a namespace declaration. Namespace declarations
414 are processed before the :attr:`StartElementHandler` is called for the element
415 on which declarations are placed.
416
417
418.. method:: xmlparser.EndNamespaceDeclHandler(prefix)
419
420 Called when the closing tag is reached for an element that contained a
421 namespace declaration. This is called once for each namespace declaration on
422 the element in the reverse of the order for which the
423 :attr:`StartNamespaceDeclHandler` was called to indicate the start of each
424 namespace declaration's scope. Calls to this handler are made after the
425 corresponding :attr:`EndElementHandler` for the end of the element.
426
427
428.. method:: xmlparser.CommentHandler(data)
429
430 Called for comments. *data* is the text of the comment, excluding the leading
431 '``<!-``\ ``-``' and trailing '``-``\ ``->``'.
432
433
434.. method:: xmlparser.StartCdataSectionHandler()
435
436 Called at the start of a CDATA section. This and :attr:`EndCdataSectionHandler`
437 are needed to be able to identify the syntactical start and end for CDATA
438 sections.
439
440
441.. method:: xmlparser.EndCdataSectionHandler()
442
443 Called at the end of a CDATA section.
444
445
446.. method:: xmlparser.DefaultHandler(data)
447
448 Called for any characters in the XML document for which no applicable handler
449 has been specified. This means characters that are part of a construct which
450 could be reported, but for which no handler has been supplied.
451
452
453.. method:: xmlparser.DefaultHandlerExpand(data)
454
455 This is the same as the :func:`DefaultHandler`, but doesn't inhibit expansion
456 of internal entities. The entity reference will not be passed to the default
457 handler.
458
459
460.. method:: xmlparser.NotStandaloneHandler()
461
462 Called if the XML document hasn't been declared as being a standalone document.
463 This happens when there is an external subset or a reference to a parameter
464 entity, but the XML declaration does not set standalone to ``yes`` in an XML
465 declaration. If this handler returns ``0``, then the parser will throw an
466 :const:`XML_ERROR_NOT_STANDALONE` error. If this handler is not set, no
467 exception is raised by the parser for this condition.
468
469
470.. method:: xmlparser.ExternalEntityRefHandler(context, base, systemId, publicId)
471
472 Called for references to external entities. *base* is the current base, as set
473 by a previous call to :meth:`SetBase`. The public and system identifiers,
474 *systemId* and *publicId*, are strings if given; if the public identifier is not
475 given, *publicId* will be ``None``. The *context* value is opaque and should
476 only be used as described below.
477
478 For external entities to be parsed, this handler must be implemented. It is
479 responsible for creating the sub-parser using
480 ``ExternalEntityParserCreate(context)``, initializing it with the appropriate
481 callbacks, and parsing the entity. This handler should return an integer; if it
482 returns ``0``, the parser will throw an
483 :const:`XML_ERROR_EXTERNAL_ENTITY_HANDLING` error, otherwise parsing will
484 continue.
485
486 If this handler is not provided, external entities are reported by the
487 :attr:`DefaultHandler` callback, if provided.
488
489
490.. _expaterror-objects:
491
492ExpatError Exceptions
493---------------------
494
495.. sectionauthor:: Fred L. Drake, Jr. <fdrake@acm.org>
496
497
498:exc:`ExpatError` exceptions have a number of interesting attributes:
499
500
501.. attribute:: ExpatError.code
502
503 Expat's internal error number for the specific error. This will match one of
504 the constants defined in the ``errors`` object from this module.
505
506 .. versionadded:: 2.1
507
508
509.. attribute:: ExpatError.lineno
510
511 Line number on which the error was detected. The first line is numbered ``1``.
512
513 .. versionadded:: 2.1
514
515
516.. attribute:: ExpatError.offset
517
518 Character offset into the line where the error occurred. The first column is
519 numbered ``0``.
520
521 .. versionadded:: 2.1
522
523
524.. _expat-example:
525
526Example
527-------
528
529The following program defines three handlers that just print out their
530arguments. ::
531
532 import xml.parsers.expat
533
534 # 3 handler functions
535 def start_element(name, attrs):
536 print 'Start element:', name, attrs
537 def end_element(name):
538 print 'End element:', name
539 def char_data(data):
540 print 'Character data:', repr(data)
541
542 p = xml.parsers.expat.ParserCreate()
543
544 p.StartElementHandler = start_element
545 p.EndElementHandler = end_element
546 p.CharacterDataHandler = char_data
547
548 p.Parse("""<?xml version="1.0"?>
549 <parent id="top"><child1 name="paul">Text goes here</child1>
550 <child2 name="fred">More text</child2>
551 </parent>""", 1)
552
553The output from this program is::
554
555 Start element: parent {'id': 'top'}
556 Start element: child1 {'name': 'paul'}
557 Character data: 'Text goes here'
558 End element: child1
559 Character data: '\n'
560 Start element: child2 {'name': 'fred'}
561 Character data: 'More text'
562 End element: child2
563 Character data: '\n'
564 End element: parent
565
566
567.. _expat-content-models:
568
569Content Model Descriptions
570--------------------------
571
572.. sectionauthor:: Fred L. Drake, Jr. <fdrake@acm.org>
573
574
575Content modules are described using nested tuples. Each tuple contains four
576values: the type, the quantifier, the name, and a tuple of children. Children
577are simply additional content module descriptions.
578
579The values of the first two fields are constants defined in the ``model`` object
580of the :mod:`xml.parsers.expat` module. These constants can be collected in two
581groups: the model type group and the quantifier group.
582
583The constants in the model type group are:
584
585
586.. data:: XML_CTYPE_ANY
587 :noindex:
588
589 The element named by the model name was declared to have a content model of
590 ``ANY``.
591
592
593.. data:: XML_CTYPE_CHOICE
594 :noindex:
595
596 The named element allows a choice from a number of options; this is used for
597 content models such as ``(A | B | C)``.
598
599
600.. data:: XML_CTYPE_EMPTY
601 :noindex:
602
603 Elements which are declared to be ``EMPTY`` have this model type.
604
605
606.. data:: XML_CTYPE_MIXED
607 :noindex:
608
609
610.. data:: XML_CTYPE_NAME
611 :noindex:
612
613
614.. data:: XML_CTYPE_SEQ
615 :noindex:
616
617 Models which represent a series of models which follow one after the other are
618 indicated with this model type. This is used for models such as ``(A, B, C)``.
619
620The constants in the quantifier group are:
621
622
623.. data:: XML_CQUANT_NONE
624 :noindex:
625
626 No modifier is given, so it can appear exactly once, as for ``A``.
627
628
629.. data:: XML_CQUANT_OPT
630 :noindex:
631
632 The model is optional: it can appear once or not at all, as for ``A?``.
633
634
635.. data:: XML_CQUANT_PLUS
636 :noindex:
637
638 The model must occur one or more times (like ``A+``).
639
640
641.. data:: XML_CQUANT_REP
642 :noindex:
643
644 The model must occur zero or more times, as for ``A*``.
645
646
647.. _expat-errors:
648
649Expat error constants
650---------------------
651
652The following constants are provided in the ``errors`` object of the
653:mod:`xml.parsers.expat` module. These constants are useful in interpreting
654some of the attributes of the :exc:`ExpatError` exception objects raised when an
655error has occurred.
656
657The ``errors`` object has the following attributes:
658
659
660.. data:: XML_ERROR_ASYNC_ENTITY
661 :noindex:
662
663
664.. data:: XML_ERROR_ATTRIBUTE_EXTERNAL_ENTITY_REF
665 :noindex:
666
667 An entity reference in an attribute value referred to an external entity instead
668 of an internal entity.
669
670
671.. data:: XML_ERROR_BAD_CHAR_REF
672 :noindex:
673
674 A character reference referred to a character which is illegal in XML (for
675 example, character ``0``, or '``&#0;``').
676
677
678.. data:: XML_ERROR_BINARY_ENTITY_REF
679 :noindex:
680
681 An entity reference referred to an entity which was declared with a notation, so
682 cannot be parsed.
683
684
685.. data:: XML_ERROR_DUPLICATE_ATTRIBUTE
686 :noindex:
687
688 An attribute was used more than once in a start tag.
689
690
691.. data:: XML_ERROR_INCORRECT_ENCODING
692 :noindex:
693
694
695.. data:: XML_ERROR_INVALID_TOKEN
696 :noindex:
697
698 Raised when an input byte could not properly be assigned to a character; for
699 example, a NUL byte (value ``0``) in a UTF-8 input stream.
700
701
702.. data:: XML_ERROR_JUNK_AFTER_DOC_ELEMENT
703 :noindex:
704
705 Something other than whitespace occurred after the document element.
706
707
708.. data:: XML_ERROR_MISPLACED_XML_PI
709 :noindex:
710
711 An XML declaration was found somewhere other than the start of the input data.
712
713
714.. data:: XML_ERROR_NO_ELEMENTS
715 :noindex:
716
717 The document contains no elements (XML requires all documents to contain exactly
718 one top-level element)..
719
720
721.. data:: XML_ERROR_NO_MEMORY
722 :noindex:
723
724 Expat was not able to allocate memory internally.
725
726
727.. data:: XML_ERROR_PARAM_ENTITY_REF
728 :noindex:
729
730 A parameter entity reference was found where it was not allowed.
731
732
733.. data:: XML_ERROR_PARTIAL_CHAR
734 :noindex:
735
736 An incomplete character was found in the input.
737
738
739.. data:: XML_ERROR_RECURSIVE_ENTITY_REF
740 :noindex:
741
742 An entity reference contained another reference to the same entity; possibly via
743 a different name, and possibly indirectly.
744
745
746.. data:: XML_ERROR_SYNTAX
747 :noindex:
748
749 Some unspecified syntax error was encountered.
750
751
752.. data:: XML_ERROR_TAG_MISMATCH
753 :noindex:
754
755 An end tag did not match the innermost open start tag.
756
757
758.. data:: XML_ERROR_UNCLOSED_TOKEN
759 :noindex:
760
761 Some token (such as a start tag) was not closed before the end of the stream or
762 the next token was encountered.
763
764
765.. data:: XML_ERROR_UNDEFINED_ENTITY
766 :noindex:
767
768 A reference was made to a entity which was not defined.
769
770
771.. data:: XML_ERROR_UNKNOWN_ENCODING
772 :noindex:
773
774 The document encoding is not supported by Expat.
775
776
777.. data:: XML_ERROR_UNCLOSED_CDATA_SECTION
778 :noindex:
779
780 A CDATA marked section was not closed.
781
782
783.. data:: XML_ERROR_EXTERNAL_ENTITY_HANDLING
784 :noindex:
785
786
787.. data:: XML_ERROR_NOT_STANDALONE
788 :noindex:
789
790 The parser determined that the document was not "standalone" though it declared
791 itself to be in the XML declaration, and the :attr:`NotStandaloneHandler` was
792 set and returned ``0``.
793
794
795.. data:: XML_ERROR_UNEXPECTED_STATE
796 :noindex:
797
798
799.. data:: XML_ERROR_ENTITY_DECLARED_IN_PE
800 :noindex:
801
802
803.. data:: XML_ERROR_FEATURE_REQUIRES_XML_DTD
804 :noindex:
805
806 An operation was requested that requires DTD support to be compiled in, but
807 Expat was configured without DTD support. This should never be reported by a
808 standard build of the :mod:`xml.parsers.expat` module.
809
810
811.. data:: XML_ERROR_CANT_CHANGE_FEATURE_ONCE_PARSING
812 :noindex:
813
814 A behavioral change was requested after parsing started that can only be changed
815 before parsing has started. This is (currently) only raised by
816 :meth:`UseForeignDTD`.
817
818
819.. data:: XML_ERROR_UNBOUND_PREFIX
820 :noindex:
821
822 An undeclared prefix was found when namespace processing was enabled.
823
824
825.. data:: XML_ERROR_UNDECLARING_PREFIX
826 :noindex:
827
828 The document attempted to remove the namespace declaration associated with a
829 prefix.
830
831
832.. data:: XML_ERROR_INCOMPLETE_PE
833 :noindex:
834
835 A parameter entity contained incomplete markup.
836
837
838.. data:: XML_ERROR_XML_DECL
839 :noindex:
840
841 The document contained no document element at all.
842
843
844.. data:: XML_ERROR_TEXT_DECL
845 :noindex:
846
847 There was an error parsing a text declaration in an external entity.
848
849
850.. data:: XML_ERROR_PUBLICID
851 :noindex:
852
853 Characters were found in the public id that are not allowed.
854
855
856.. data:: XML_ERROR_SUSPENDED
857 :noindex:
858
859 The requested operation was made on a suspended parser, but isn't allowed. This
860 includes attempts to provide additional input or to stop the parser.
861
862
863.. data:: XML_ERROR_NOT_SUSPENDED
864 :noindex:
865
866 An attempt to resume the parser was made when the parser had not been suspended.
867
868
869.. data:: XML_ERROR_ABORTED
870 :noindex:
871
872 This should not be reported to Python applications.
873
874
875.. data:: XML_ERROR_FINISHED
876 :noindex:
877
878 The requested operation was made on a parser which was finished parsing input,
879 but isn't allowed. This includes attempts to provide additional input or to
880 stop the parser.
881
882
883.. data:: XML_ERROR_SUSPEND_PE
884 :noindex:
885