pyexpat - Python wrapper for Expat parser.
| Use Case | Command | Description |
|---|---|---|
| Create parser | parser = ParserCreate() | Return a new XML parser object |
| Parse XML data | parser.Parse(data, isfinal=False) | Parse XML data; set isfinal=True at end of input |
| Parse from file | parser.ParseFile(file) | Parse XML data from a file-like object |
| Set start element handler | parser.StartElementHandler = handler | Assign callable for startβtag events |
| Get error message | ErrorString(code) | Return a humanβreadable string for a numeric error code |
| Control parameter entity parsing | parser.SetParamEntityParsing(flag) | Use XML_PARAM_ENTITY_PARSING_* constants |
| Set base URL | parser.SetBase(base) | Set the base URL for relative references |
| Create external entity parser | parser.ExternalEntityParserCreate(...) | Build a parser for an external entity |
errorsmodelInherits from builtins.Exception.
Method resolution order: ExpatError β builtins.Exception β builtins.BaseException β builtins.object
__weakref__ β list of weak references to the object (if defined)__init__(self, /, *args, **kwargs) β Initialize self. See help(type(self)) for accurate signature.__new__(*args, **kwargs) from builtins.type β Create and return a new object. See help(type(self)) for accurate signature.__delattr__(self, name, /) β Implement delattr(self, name).__getattribute__(self, name, /) β Return getattr(self, name).__reduce__(...) β Helper for pickle.__repr__(self, /) β Return repr(self).__setattr__(self, name, value, /) β Implement setattr(self, name, value).__setstate__(...)__str__(self, /) β Return str(self).with_traceback(...) β Exception.with_traceback(tb) β set self.__traceback__ to tb and return self.__cause__ β exception cause__context__ β exception context__dict____suppress_context____traceback__argsXML parser class. Also aliased as XMLParserType.
ExternalEntityParserCreate(...) β Create a parser for parsing an external entity based on the information passed to the ExternalEntityRefHandler.GetBase(self, /) β Return base URL string for the parser.GetInputContext(self, /) β Return the untranslated text of the input that caused the current event. If the event was generated by a large amount of text (such as a start tag for an element with many attributes), not all of the text may be available.Parse(self, data, isfinal=False, /) β Parse XML data. isfinal should be true at end of input.ParseFile(self, file, /) β Parse XML data from file-like object.SetBase(self, base, /) β Set the base URL for the parser.SetParamEntityParsing(self, flag, /) β Controls parsing of parameter entities (including the external DTD subset). Possible flag values are XML_PARAM_ENTITY_PARSING_NEVER, XML_PARAM_ENTITY_PARSING_UNLESS_STANDALONE and XML_PARAM_ENTITY_PARSING_ALWAYS. Returns true if setting the flag was successful.UseForeignDTD(self, flag=True, /) β Allows the application to provide an artificial external subset if one is not specified as part of the document instance. This readily allows the use of a 'default' document type controlled by the application, while still getting the advantage of providing document type information to the parser. flag defaults to True if not provided.AttlistDeclHandlerCharacterDataHandlerCommentHandlerCurrentByteIndexCurrentColumnNumberCurrentLineNumberDefaultHandlerDefaultHandlerExpandElementDeclHandlerEndCdataSectionHandlerEndDoctypeDeclHandlerEndElementHandlerEndNamespaceDeclHandlerEntityDeclHandlerErrorByteIndexErrorCodeErrorColumnNumberErrorLineNumberExternalEntityRefHandlerNotStandaloneHandlerNotationDeclHandlerProcessingInstructionHandlerSkippedEntityHandlerStartCdataSectionHandlerStartDoctypeDeclHandlerStartElementHandlerStartNamespaceDeclHandlerUnparsedEntityDeclHandlerXmlDeclHandlerbuffer_sizebuffer_textbuffer_usedinternnamespace_prefixesordered_attributesspecified_attributesπ error is an alias for ExpatError.
ErrorString(code, /) β Returns a string error message for the given numeric code.ParserCreate(...) β Return a new XML parser object.EXPAT_VERSION = 'expat_2.4.7' β Expat library version string.XML_PARAM_ENTITY_PARSING_ALWAYS = 2XML_PARAM_ENTITY_PARSING_NEVER = 0XML_PARAM_ENTITY_PARSING_UNLESS_STANDALONE = 1expat_CAPI = <capsule object "pyexpat.expat_CAPI"> β C API capsule.features = [('sizeof(XML_Char)', 1), ('sizeof(XML_LChar)', 1), ('XML_D... β List of feature tuples.native_encoding = 'UTF-8' β Native encoding used by the parser.version_info = (2, 4, 7) β Version info tuple.(built-in)
Generated by phpman v4.9.27 · Markdown · JSON · MCP Author: Che Dong Under GNU General Public License
2026-07-18 13:20 @216.73.216.114
CrawledBy Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)
Enhanced by LLM: deepseek-v4-flash / taotoken.net / www.chedong.com - original format