XML Processing Modules
xml.parsers.expat.model
Provides numeric constants describing Expat DTD element content models and quantifiers. ElementDeclHandler receives a nested tuple representing a declaration. These constants describe grammar structure, not a promise of DTD validation; Expat is non-validating. The example uses a small internal declaration with no external entities.
Formal Syntax & Structure
python syntaxpython
import xml.parsers.expat.modelReturn Value
module
Module namespace available through import; import is a statement, not a value-returning expression.
Working Example
Example Snippetpython
from xml.parsers.expat import ParserCreate, modelparser = ParserCreate()kinds = []parser.ElementDeclHandler = lambda name, spec: kinds.append(spec[0])parser.Parse("<!DOCTYPE r [<!ELEMENT r EMPTY>]><r/>", True)print(kinds == [model.XML_CTYPE_EMPTY])