Issue 36227: Add default_namespace argument to xml.etree.ElementTree.tostring()
Created on 2019-03-07 18:57 by Bernt.Røskar.Brenna, last changed 2022-04-11 14:59 by admin. This issue is now closed.
Messages (9)
msg337428 - (view)
Author: Bernt Røskar Brenna (Bernt.Røskar.Brenna) *
Date: 2019-03-07 18:57
Date: 2019-03-08 08:37
Date: 2019-03-08 08:50
Date: 2019-03-08 08:58
Date: 2019-03-08 09:51
Date: 2019-04-14 08:07
Date: 2019-04-14 08:16
default_namespace is often used when serializing ET elements. tostring() is mainly a wrapper around ElementTree.write(), and it is therefore natural that it mirrors write's argument. tostring() already passes encoding, method and short_empty_elements to write.msg337455 - (view) Author: Stefan Behnel (scoder) *
Date: 2019-03-08 08:37
The feature seems reasonable to me and the patch looks good.msg337456 - (view) Author: Serhiy Storchaka (serhiy.storchaka) *
Date: 2019-03-08 08:50
See also issue31256. I do not know what is better: make tostring() to accept all options of write(), or keep it simpler. What strategy lxml supports?msg337458 - (view) Author: Stefan Behnel (scoder) *
Date: 2019-03-08 08:58
lxml does not support the "default_namespace" option specifically (because its tree model preserves namespace prefixes), but it generally makes all (justifiable) serialisation options available to both tostring() and ET.write(). I think the same should apply to ElementTree. Both the "default_namespace" and "doctype" options seem useful regardless of the serialisation target.msg337460 - (view) Author: Serhiy Storchaka (serhiy.storchaka) *
Date: 2019-03-08 09:51
Okay. Bernt, do you mind to add also the xml_declaration option in PR 12225 or create a separate PR for issue31256?msg337473 - (view) Author: Bernt Røskar Brenna (Bernt.Røskar.Brenna) * Date: 2019-03-08 13:28
I will add xml_declaration and push to the existing PR.msg337478 - (view) Author: Bernt Røskar Brenna (Bernt.Røskar.Brenna) * Date: 2019-03-08 14:02
I pushed changes to the PR. I also added xml_declaration and default_namespace to the tostringlist() method.msg340190 - (view) Author: Stefan Behnel (scoder) *
Date: 2019-04-14 08:07
New changeset ffca16e25a70fd44a87b13b379b5ec0c7a11e926 by Stefan Behnel (Bernt Røskar Brenna) in branch 'master': bpo-36227: ElementTree.tostring() default_namespace and xml_declaration arguments (GH-12225) https://github.com/python/cpython/commit/ffca16e25a70fd44a87b13b379b5ec0c7a11e926msg340193 - (view) Author: Stefan Behnel (scoder) *
Date: 2019-04-14 08:16
Thank you for you contribution.