Issue 36874: Support CDATA by xml.etree.(c)ElementTree (original) (raw)

Issue36874

Created on 2019-05-10 09:51 by Pierre van de Laar, last changed 2022-04-11 14:59 by admin.

Messages (2)
msg342067 - (view) Author: Pierre van de Laar (Pierre van de Laar) Date: 2019-05-10 09:51
I would like to add information to CDATA in an Xml Tree. Turns out I am not the only one: https://stackoverflow.com/questions/174890/how-to-output-cdata-using-elementtree Can the library be extended to also support CDATA (similar to Comment)? Saves a lot of hacking...
msg342072 - (view) Author: Stefan Behnel (scoder) * (Python committer) Date: 2019-05-10 12:32
PR welcome. This is how lxml implements it: https://lxml.de/api.html#cdata Tests are here: https://github.com/lxml/lxml/blob/1a2db33aa8b9619c1caf407167567d5cca0b9019/src/lxml/tests/test_etree.py#L1692-L1749 I guess it won't look perfectly the same in ElementTree in the end, but it might be enough to implement a string wrapper class (or even str subclass?), and then maybe special-case it in the serialiser (probably needed for the escaping). However, anything that relieves the serialiser from doing special work for this exceptional case might be a good idea.
History
Date User Action Args
2022-04-11 14:59:15 admin set github: 81055
2019-05-10 12:32:09 scoder set stage: needs patchmessages: + versions: + Python 3.8
2019-05-10 10:03:53 xtreak set nosy: + scoder
2019-05-10 09:51:15 Pierre van de Laar create