blob: 87ed501408014dff5d404c9acb765125ec26545b [file] [log] [blame]
Georg Brandl116aa622007-08-15 14:28:22 +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` and :attr:`specified_attributes` set to the values of
160 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.specified_attributes
227
228 If set to a non-zero integer, the parser will report only those attributes which
229 were specified in the document instance and not those which were derived from
230 attribute declarations. Applications which set this need to be especially
231 careful to use what additional information is available from the declarations as
232 needed to comply with the standards for the behavior of XML processors. By
233 default, this attribute is false; it may be changed at any time.
234
235 .. versionadded:: 2.1
236
237The following attributes contain values relating to the most recent error
238encountered by an :class:`xmlparser` object, and will only have correct values
239once a call to :meth:`Parse` or :meth:`ParseFile` has raised a
240:exc:`xml.parsers.expat.ExpatError` exception.
241
242
243.. attribute:: xmlparser.ErrorByteIndex
244
245 Byte index at which an error occurred.
246
247
248.. attribute:: xmlparser.ErrorCode
249
250 Numeric code specifying the problem. This value can be passed to the
251 :func:`ErrorString` function, or compared to one of the constants defined in the
252 ``errors`` object.
253
254
255.. attribute:: xmlparser.ErrorColumnNumber
256
257 Column number at which an error occurred.
258
259
260.. attribute:: xmlparser.ErrorLineNumber
261
262 Line number at which an error occurred.
263
264The following attributes contain values relating to the current parse location
265in an :class:`xmlparser` object. During a callback reporting a parse event they
266indicate the location of the first of the sequence of characters that generated
267the event. When called outside of a callback, the position indicated will be
268just past the last parse event (regardless of whether there was an associated
269callback).
270
271.. versionadded:: 2.4
272
273
274.. attribute:: xmlparser.CurrentByteIndex
275
276 Current byte index in the parser input.
277
278
279.. attribute:: xmlparser.CurrentColumnNumber
280
281 Current column number in the parser input.
282
283
284.. attribute:: xmlparser.CurrentLineNumber
285
286 Current line number in the parser input.
287
288Here is the list of handlers that can be set. To set a handler on an
289:class:`xmlparser` object *o*, use ``o.handlername = func``. *handlername* must
290be taken from the following list, and *func* must be a callable object accepting
291the correct number of arguments. The arguments are all strings, unless
292otherwise stated.
293
294
295.. method:: xmlparser.XmlDeclHandler(version, encoding, standalone)
296
297 Called when the XML declaration is parsed. The XML declaration is the
298 (optional) declaration of the applicable version of the XML recommendation, the
299 encoding of the document text, and an optional "standalone" declaration.
300 *version* and *encoding* will be strings, and *standalone* will be ``1`` if the
301 document is declared standalone, ``0`` if it is declared not to be standalone,
302 or ``-1`` if the standalone clause was omitted. This is only available with
303 Expat version 1.95.0 or newer.
304
305 .. versionadded:: 2.1
306
307
308.. method:: xmlparser.StartDoctypeDeclHandler(doctypeName, systemId, publicId, has_internal_subset)
309
310 Called when Expat begins parsing the document type declaration (``<!DOCTYPE
311 ...``). The *doctypeName* is provided exactly as presented. The *systemId* and
312 *publicId* parameters give the system and public identifiers if specified, or
313 ``None`` if omitted. *has_internal_subset* will be true if the document
314 contains and internal document declaration subset. This requires Expat version
315 1.2 or newer.
316
317
318.. method:: xmlparser.EndDoctypeDeclHandler()
319
320 Called when Expat is done parsing the document type declaration. This requires
321 Expat version 1.2 or newer.
322
323
324.. method:: xmlparser.ElementDeclHandler(name, model)
325
326 Called once for each element type declaration. *name* is the name of the
327 element type, and *model* is a representation of the content model.
328
329
330.. method:: xmlparser.AttlistDeclHandler(elname, attname, type, default, required)
331
332 Called for each declared attribute for an element type. If an attribute list
333 declaration declares three attributes, this handler is called three times, once
334 for each attribute. *elname* is the name of the element to which the
335 declaration applies and *attname* is the name of the attribute declared. The
336 attribute type is a string passed as *type*; the possible values are
337 ``'CDATA'``, ``'ID'``, ``'IDREF'``, ... *default* gives the default value for
338 the attribute used when the attribute is not specified by the document instance,
339 or ``None`` if there is no default value (``#IMPLIED`` values). If the
340 attribute is required to be given in the document instance, *required* will be
341 true. This requires Expat version 1.95.0 or newer.
342
343
344.. method:: xmlparser.StartElementHandler(name, attributes)
345
346 Called for the start of every element. *name* is a string containing the
347 element name, and *attributes* is a dictionary mapping attribute names to their
348 values.
349
350
351.. method:: xmlparser.EndElementHandler(name)
352
353 Called for the end of every element.
354
355
356.. method:: xmlparser.ProcessingInstructionHandler(target, data)
357
358 Called for every processing instruction.
359
360
361.. method:: xmlparser.CharacterDataHandler(data)
362
363 Called for character data. This will be called for normal character data, CDATA
364 marked content, and ignorable whitespace. Applications which must distinguish
365 these cases can use the :attr:`StartCdataSectionHandler`,
366 :attr:`EndCdataSectionHandler`, and :attr:`ElementDeclHandler` callbacks to
367 collect the required information.
368
369
370.. method:: xmlparser.UnparsedEntityDeclHandler(entityName, base, systemId, publicId, notationName)
371
372 Called for unparsed (NDATA) entity declarations. This is only present for
373 version 1.2 of the Expat library; for more recent versions, use
374 :attr:`EntityDeclHandler` instead. (The underlying function in the Expat
375 library has been declared obsolete.)
376
377
378.. method:: xmlparser.EntityDeclHandler(entityName, is_parameter_entity, value, base, systemId, publicId, notationName)
379
380 Called for all entity declarations. For parameter and internal entities,
381 *value* will be a string giving the declared contents of the entity; this will
382 be ``None`` for external entities. The *notationName* parameter will be
383 ``None`` for parsed entities, and the name of the notation for unparsed
384 entities. *is_parameter_entity* will be true if the entity is a parameter entity
385 or false for general entities (most applications only need to be concerned with
386 general entities). This is only available starting with version 1.95.0 of the
387 Expat library.
388
389 .. versionadded:: 2.1
390
391
392.. method:: xmlparser.NotationDeclHandler(notationName, base, systemId, publicId)
393
394 Called for notation declarations. *notationName*, *base*, and *systemId*, and
395 *publicId* are strings if given. If the public identifier is omitted,
396 *publicId* will be ``None``.
397
398
399.. method:: xmlparser.StartNamespaceDeclHandler(prefix, uri)
400
401 Called when an element contains a namespace declaration. Namespace declarations
402 are processed before the :attr:`StartElementHandler` is called for the element
403 on which declarations are placed.
404
405
406.. method:: xmlparser.EndNamespaceDeclHandler(prefix)
407
408 Called when the closing tag is reached for an element that contained a
409 namespace declaration. This is called once for each namespace declaration on
410 the element in the reverse of the order for which the
411 :attr:`StartNamespaceDeclHandler` was called to indicate the start of each
412 namespace declaration's scope. Calls to this handler are made after the
413 corresponding :attr:`EndElementHandler` for the end of the element.
414
415
416.. method:: xmlparser.CommentHandler(data)
417
418 Called for comments. *data* is the text of the comment, excluding the leading
419 '``<!-``\ ``-``' and trailing '``-``\ ``->``'.
420
421
422.. method:: xmlparser.StartCdataSectionHandler()
423
424 Called at the start of a CDATA section. This and :attr:`EndCdataSectionHandler`
425 are needed to be able to identify the syntactical start and end for CDATA
426 sections.
427
428
429.. method:: xmlparser.EndCdataSectionHandler()
430
431 Called at the end of a CDATA section.
432
433
434.. method:: xmlparser.DefaultHandler(data)
435
436 Called for any characters in the XML document for which no applicable handler
437 has been specified. This means characters that are part of a construct which
438 could be reported, but for which no handler has been supplied.
439
440
441.. method:: xmlparser.DefaultHandlerExpand(data)
442
443 This is the same as the :func:`DefaultHandler`, but doesn't inhibit expansion
444 of internal entities. The entity reference will not be passed to the default
445 handler.
446
447
448.. method:: xmlparser.NotStandaloneHandler()
449
450 Called if the XML document hasn't been declared as being a standalone document.
451 This happens when there is an external subset or a reference to a parameter
452 entity, but the XML declaration does not set standalone to ``yes`` in an XML
453 declaration. If this handler returns ``0``, then the parser will throw an
454 :const:`XML_ERROR_NOT_STANDALONE` error. If this handler is not set, no
455 exception is raised by the parser for this condition.
456
457
458.. method:: xmlparser.ExternalEntityRefHandler(context, base, systemId, publicId)
459
460 Called for references to external entities. *base* is the current base, as set
461 by a previous call to :meth:`SetBase`. The public and system identifiers,
462 *systemId* and *publicId*, are strings if given; if the public identifier is not
463 given, *publicId* will be ``None``. The *context* value is opaque and should
464 only be used as described below.
465
466 For external entities to be parsed, this handler must be implemented. It is
467 responsible for creating the sub-parser using
468 ``ExternalEntityParserCreate(context)``, initializing it with the appropriate
469 callbacks, and parsing the entity. This handler should return an integer; if it
470 returns ``0``, the parser will throw an
471 :const:`XML_ERROR_EXTERNAL_ENTITY_HANDLING` error, otherwise parsing will
472 continue.
473
474 If this handler is not provided, external entities are reported by the
475 :attr:`DefaultHandler` callback, if provided.
476
477
478.. _expaterror-objects:
479
480ExpatError Exceptions
481---------------------
482
483.. sectionauthor:: Fred L. Drake, Jr. <fdrake@acm.org>
484
485
486:exc:`ExpatError` exceptions have a number of interesting attributes:
487
488
489.. attribute:: ExpatError.code
490
491 Expat's internal error number for the specific error. This will match one of
492 the constants defined in the ``errors`` object from this module.
493
494 .. versionadded:: 2.1
495
496
497.. attribute:: ExpatError.lineno
498
499 Line number on which the error was detected. The first line is numbered ``1``.
500
501 .. versionadded:: 2.1
502
503
504.. attribute:: ExpatError.offset
505
506 Character offset into the line where the error occurred. The first column is
507 numbered ``0``.
508
509 .. versionadded:: 2.1
510
511
512.. _expat-example:
513
514Example
515-------
516
517The following program defines three handlers that just print out their
518arguments. ::
519
520 import xml.parsers.expat
521
522 # 3 handler functions
523 def start_element(name, attrs):
524 print 'Start element:', name, attrs
525 def end_element(name):
526 print 'End element:', name
527 def char_data(data):
528 print 'Character data:', repr(data)
529
530 p = xml.parsers.expat.ParserCreate()
531
532 p.StartElementHandler = start_element
533 p.EndElementHandler = end_element
534 p.CharacterDataHandler = char_data
535
536 p.Parse("""<?xml version="1.0"?>
537 <parent id="top"><child1 name="paul">Text goes here</child1>
538 <child2 name="fred">More text</child2>
539 </parent>""", 1)
540
541The output from this program is::
542
543 Start element: parent {'id': 'top'}
544 Start element: child1 {'name': 'paul'}
545 Character data: 'Text goes here'
546 End element: child1
547 Character data: '\n'
548 Start element: child2 {'name': 'fred'}
549 Character data: 'More text'
550 End element: child2
551 Character data: '\n'
552 End element: parent
553
554
555.. _expat-content-models:
556
557Content Model Descriptions
558--------------------------
559
560.. sectionauthor:: Fred L. Drake, Jr. <fdrake@acm.org>
561
562
563Content modules are described using nested tuples. Each tuple contains four
564values: the type, the quantifier, the name, and a tuple of children. Children
565are simply additional content module descriptions.
566
567The values of the first two fields are constants defined in the ``model`` object
568of the :mod:`xml.parsers.expat` module. These constants can be collected in two
569groups: the model type group and the quantifier group.
570
571The constants in the model type group are:
572
573
574.. data:: XML_CTYPE_ANY
575 :noindex:
576
577 The element named by the model name was declared to have a content model of
578 ``ANY``.
579
580
581.. data:: XML_CTYPE_CHOICE
582 :noindex:
583
584 The named element allows a choice from a number of options; this is used for
585 content models such as ``(A | B | C)``.
586
587
588.. data:: XML_CTYPE_EMPTY
589 :noindex:
590
591 Elements which are declared to be ``EMPTY`` have this model type.
592
593
594.. data:: XML_CTYPE_MIXED
595 :noindex:
596
597
598.. data:: XML_CTYPE_NAME
599 :noindex:
600
601
602.. data:: XML_CTYPE_SEQ
603 :noindex:
604
605 Models which represent a series of models which follow one after the other are
606 indicated with this model type. This is used for models such as ``(A, B, C)``.
607
608The constants in the quantifier group are:
609
610
611.. data:: XML_CQUANT_NONE
612 :noindex:
613
614 No modifier is given, so it can appear exactly once, as for ``A``.
615
616
617.. data:: XML_CQUANT_OPT
618 :noindex:
619
620 The model is optional: it can appear once or not at all, as for ``A?``.
621
622
623.. data:: XML_CQUANT_PLUS
624 :noindex:
625
626 The model must occur one or more times (like ``A+``).
627
628
629.. data:: XML_CQUANT_REP
630 :noindex:
631
632 The model must occur zero or more times, as for ``A*``.
633
634
635.. _expat-errors:
636
637Expat error constants
638---------------------
639
640The following constants are provided in the ``errors`` object of the
641:mod:`xml.parsers.expat` module. These constants are useful in interpreting
642some of the attributes of the :exc:`ExpatError` exception objects raised when an
643error has occurred.
644
645The ``errors`` object has the following attributes:
646
647
648.. data:: XML_ERROR_ASYNC_ENTITY
649 :noindex:
650
651
652.. data:: XML_ERROR_ATTRIBUTE_EXTERNAL_ENTITY_REF
653 :noindex:
654
655 An entity reference in an attribute value referred to an external entity instead
656 of an internal entity.
657
658
659.. data:: XML_ERROR_BAD_CHAR_REF
660 :noindex:
661
662 A character reference referred to a character which is illegal in XML (for
663 example, character ``0``, or '``&#0;``').
664
665
666.. data:: XML_ERROR_BINARY_ENTITY_REF
667 :noindex:
668
669 An entity reference referred to an entity which was declared with a notation, so
670 cannot be parsed.
671
672
673.. data:: XML_ERROR_DUPLICATE_ATTRIBUTE
674 :noindex:
675
676 An attribute was used more than once in a start tag.
677
678
679.. data:: XML_ERROR_INCORRECT_ENCODING
680 :noindex:
681
682
683.. data:: XML_ERROR_INVALID_TOKEN
684 :noindex:
685
686 Raised when an input byte could not properly be assigned to a character; for
687 example, a NUL byte (value ``0``) in a UTF-8 input stream.
688
689
690.. data:: XML_ERROR_JUNK_AFTER_DOC_ELEMENT
691 :noindex:
692
693 Something other than whitespace occurred after the document element.
694
695
696.. data:: XML_ERROR_MISPLACED_XML_PI
697 :noindex:
698
699 An XML declaration was found somewhere other than the start of the input data.
700
701
702.. data:: XML_ERROR_NO_ELEMENTS
703 :noindex:
704
705 The document contains no elements (XML requires all documents to contain exactly
706 one top-level element)..
707
708
709.. data:: XML_ERROR_NO_MEMORY
710 :noindex:
711
712 Expat was not able to allocate memory internally.
713
714
715.. data:: XML_ERROR_PARAM_ENTITY_REF
716 :noindex:
717
718 A parameter entity reference was found where it was not allowed.
719
720
721.. data:: XML_ERROR_PARTIAL_CHAR
722 :noindex:
723
724 An incomplete character was found in the input.
725
726
727.. data:: XML_ERROR_RECURSIVE_ENTITY_REF
728 :noindex:
729
730 An entity reference contained another reference to the same entity; possibly via
731 a different name, and possibly indirectly.
732
733
734.. data:: XML_ERROR_SYNTAX
735 :noindex:
736
737 Some unspecified syntax error was encountered.
738
739
740.. data:: XML_ERROR_TAG_MISMATCH
741 :noindex:
742
743 An end tag did not match the innermost open start tag.
744
745
746.. data:: XML_ERROR_UNCLOSED_TOKEN
747 :noindex:
748
749 Some token (such as a start tag) was not closed before the end of the stream or
750 the next token was encountered.
751
752
753.. data:: XML_ERROR_UNDEFINED_ENTITY
754 :noindex:
755
756 A reference was made to a entity which was not defined.
757
758
759.. data:: XML_ERROR_UNKNOWN_ENCODING
760 :noindex:
761
762 The document encoding is not supported by Expat.
763
764
765.. data:: XML_ERROR_UNCLOSED_CDATA_SECTION
766 :noindex:
767
768 A CDATA marked section was not closed.
769
770
771.. data:: XML_ERROR_EXTERNAL_ENTITY_HANDLING
772 :noindex:
773
774
775.. data:: XML_ERROR_NOT_STANDALONE
776 :noindex:
777
778 The parser determined that the document was not "standalone" though it declared
779 itself to be in the XML declaration, and the :attr:`NotStandaloneHandler` was
780 set and returned ``0``.
781
782
783.. data:: XML_ERROR_UNEXPECTED_STATE
784 :noindex:
785
786
787.. data:: XML_ERROR_ENTITY_DECLARED_IN_PE
788 :noindex:
789
790
791.. data:: XML_ERROR_FEATURE_REQUIRES_XML_DTD
792 :noindex:
793
794 An operation was requested that requires DTD support to be compiled in, but
795 Expat was configured without DTD support. This should never be reported by a
796 standard build of the :mod:`xml.parsers.expat` module.
797
798
799.. data:: XML_ERROR_CANT_CHANGE_FEATURE_ONCE_PARSING
800 :noindex:
801
802 A behavioral change was requested after parsing started that can only be changed
803 before parsing has started. This is (currently) only raised by
804 :meth:`UseForeignDTD`.
805
806
807.. data:: XML_ERROR_UNBOUND_PREFIX
808 :noindex:
809
810 An undeclared prefix was found when namespace processing was enabled.
811
812
813.. data:: XML_ERROR_UNDECLARING_PREFIX
814 :noindex:
815
816 The document attempted to remove the namespace declaration associated with a
817 prefix.
818
819
820.. data:: XML_ERROR_INCOMPLETE_PE
821 :noindex:
822
823 A parameter entity contained incomplete markup.
824
825
826.. data:: XML_ERROR_XML_DECL
827 :noindex:
828
829 The document contained no document element at all.
830
831
832.. data:: XML_ERROR_TEXT_DECL
833 :noindex:
834
835 There was an error parsing a text declaration in an external entity.
836
837
838.. data:: XML_ERROR_PUBLICID
839 :noindex:
840
841 Characters were found in the public id that are not allowed.
842
843
844.. data:: XML_ERROR_SUSPENDED
845 :noindex:
846
847 The requested operation was made on a suspended parser, but isn't allowed. This
848 includes attempts to provide additional input or to stop the parser.
849
850
851.. data:: XML_ERROR_NOT_SUSPENDED
852 :noindex:
853
854 An attempt to resume the parser was made when the parser had not been suspended.
855
856
857.. data:: XML_ERROR_ABORTED
858 :noindex:
859
860 This should not be reported to Python applications.
861
862
863.. data:: XML_ERROR_FINISHED
864 :noindex:
865
866 The requested operation was made on a parser which was finished parsing input,
867 but isn't allowed. This includes attempts to provide additional input or to
868 stop the parser.
869
870
871.. data:: XML_ERROR_SUSPEND_PE
872 :noindex:
873