This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: xml.etree.ElementTree: add support for doctype in tostring method
Type: enhancement Stage: resolved
Components: XML Versions: Python 3.8
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: Bernt.Røskar.Brenna, bastik, iritkatriel, scoder, sucharik
Priority: normal Keywords: patch

Created on 2017-08-22 08:01 by bastik, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 12225 Bernt.Røskar.Brenna, 2019-03-08 14:03
Messages (5)
msg300673 - (view) Author: (bastik) Date: 2017-08-22 08:01
When trying to generate an XML file with 'xml.etree.ElementTree', there is no way to specify a doctype (example below).

The 'xml.etree.ElementTree.ElementTree.write' method has a 'xml_declaration' flag, which can be used as workaround, but there is no such flag for 'xml.etree.ElementTree.tostring' (and it is not always desirable to write the XML document directly to file). Please compare the corresponding flags in lxml.

Here is an example for a document I would like to generate and convert to string:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html><body>text</body></html>
msg337479 - (view) Author: Bernt Røskar Brenna (Bernt.Røskar.Brenna) * Date: 2019-03-08 14:05
See also: https://bugs.python.org/issue36227

PR: https://github.com/python/cpython/pull/12225
msg377718 - (view) Author: Irit Katriel (iritkatriel) * (Python committer) Date: 2020-09-30 19:03
It looks like PR 12225 resolved this issue. Can this be closed then?
msg377742 - (view) Author: Stefan Behnel (scoder) * (Python committer) Date: 2020-10-01 08:04
Yes, it fixed already. Thanks!
msg399629 - (view) Author: Danya Sucharik (sucharik) Date: 2021-08-15 22:46
May I aks, how it to add a doctype now?
History
Date User Action Args
2022-04-11 14:58:51adminsetgithub: 75439
2021-08-15 22:46:41suchariksetnosy: + sucharik

messages: + msg399629
versions: + Python 3.8, - Python 3.5
2020-10-01 08:04:49scodersetstatus: open -> closed

nosy: + scoder
messages: + msg377742

resolution: fixed
stage: patch review -> resolved
2020-09-30 19:03:21iritkatrielsetnosy: + iritkatriel
messages: + msg377718
2019-03-08 14:05:43Bernt.Røskar.Brennasetnosy: + Bernt.Røskar.Brenna
messages: + msg337479
2019-03-08 14:03:48Bernt.Røskar.Brennasetkeywords: + patch
stage: patch review
pull_requests: + pull_request12225
2017-08-22 08:01:08bastikcreate