On this page
pyexpat.ParserCreate
Prev: pyexpat.ExpatError | Up: pyexpat | Next: pyexpat.XMLParserType
Rel: pyexpat.error, pyexpat.ErrorString, pyexpat.ExpatError, pyexpat.XMLParserType
Ref: docs.python.org — pyexpat.ParserCreate
Tags: #public #python3 #stdlib #pyexpat
Import
import pyexpat
from pyexpat import ParserCreate
Signature & Overview
pyexpat.ParserCreate(...)
Return a new XML parser object.
Usage
import pyexpat
tags: list[str] = []
p = pyexpat.ParserCreate()
p.StartElementHandler = lambda name, attrs: tags.append(name)
p.Parse(b"<root><item/></root>", True)
assert tags == ["root", "item"]
Gotchas
- One-shot per document: Create a fresh parser for each XML document, and buffer
CharacterDataHandlerchunks untilEndElementHandler.
REPL Inspect
from pyexpat import ParserCreate
help(ParserCreate)
Linked from
Related notes
- tuts/python3/stdlib_module/pyexpat/error Linked here; links to this page; shared tags: #pyexpat, #stdlib
- tuts/python3/stdlib_module/pyexpat/ErrorString Linked here; links to this page; shared tags: #pyexpat, #stdlib
- tuts/python3/stdlib_module/pyexpat/ExpatError Linked here; links to this page; shared tags: #pyexpat, #stdlib
- tuts/python3/stdlib_module/pyexpat/XMLParserType Linked here; links to this page; shared tags: #pyexpat, #stdlib
- tuts/python3/stdlib_module/pyexpat Linked here; links to this page; shared tags: #stdlib
- tuts/c/stdlib shared tags: #stdlib
- tuts/c/stdlib/assert shared tags: #stdlib
- tuts/c/stdlib/assert/assert shared tags: #stdlib
- tuts/c/stdlib/assert/static_assert shared tags: #stdlib
- tuts/c/stdlib/ctype shared tags: #stdlib