>>> import sys; sys.modules['_elementtree'] = None
>>> import xml.etree.ElementTree as ET
>>> class Target:
... def doctype(self, *args): print(args)
... def close(self): pass
...
>>> ET.XMLParser(target=Target()).feed('<!DOCTYPE html><html/>')
>>> ET.XMLParser(target=Target()).feed('<!DOCTYPE r SYSTEM "r.dtd"><r/>')
('r', None, 'r.dtd')
Bug report
The pure Python implementation of
xml.etree.ElementTree.XMLParserdoes not call thedoctype()method of the target for a document type declaration without an external identifier, like<!DOCTYPE html>or<!DOCTYPE r [<!ENTITY e "v">]>. The C implementation calls it.The C implementation prints
('html', None, None)for the first document.The Python implementation does not use the
StartDoctypeDeclHandlerof Expat. It reconstructs the declaration from the tokens passed to the default handler, and only reports it aftername SYSTEM "..."orname PUBLIC "..." "...". If>or[follows the name, nothing is reported.Linked PRs