Remove some unused code and docstring descriptions.
Some references to a removed c14n serialization method remained in ElementTree.py. Attempting to use method='c14n' in the write() method would result in ValueError: unknown method 'c14n'.
Removes the write_c14n() method that uses method='c14n' and also raises the same error.
Has this already been discussed elsewhere?
This is a minor feature, which does not need previous discussion elsewhere
Hmm, right. Fredrik's original ElementC14N.py module never made its way into CPython.
lxml uses method="c14n" for C14N version 1 and method="c14n2" for version 2. xml.etree could support the latter but not currently the first, though that is the one that is documented.
Since this never worked, removing it seems fine.
Making method="c14n2" work in CPython would require a bit of work to map an existing tree to the C14NWriterTarget (or a parser target in general). Certainly a cool feature, but it would be a new feature, independent of the currently documented c14n serialisation method. lxml uses its iterwalk() tool for this (like iterparse(), just not as a parser but for existing trees): https://github.com/lxml/lxml/blob/0e9989972a6c430277f962054db9c4cf19ec28c0/src/lxml/serializer.pxi#L928-L948
But this could probably be implemented quite easily using a recursive tree walker function.
So, yes, remove the existing dead&confusing option and method, and then (independently) consider adding method="c14n2" as a new feature, duplicating the C14N serialisation options with_comments and strip_text to ET.write() and tostring(). (Or, which might be a more general feature, allow serialising to a parser Target object.)
Activity
danielquinn commented on Apr 21, 2025
I just wasted about an hour trying to figure out why c14n wasn't working, only to find this issue. Removal sounds like an obvious move.
serhiy-storchaka commented on May 24, 2026
@scoder, what are your thoughts?
scoder commented on May 24, 2026
Hmm, right. Fredrik's original ElementC14N.py module never made its way into CPython.
lxml uses method="c14n" for C14N version 1 and method="c14n2" for version 2. xml.etree could support the latter but not currently the first, though that is the one that is documented.
Since this never worked, removing it seems fine.
Making method="c14n2" work in CPython would require a bit of work to map an existing tree to the C14NWriterTarget (or a parser target in general). Certainly a cool feature, but it would be a new feature, independent of the currently documented c14n serialisation method. lxml uses its iterwalk() tool for this (like iterparse(), just not as a parser but for existing trees):
https://github.com/lxml/lxml/blob/0e9989972a6c430277f962054db9c4cf19ec28c0/src/lxml/serializer.pxi#L928-L948
But this could probably be implemented quite easily using a recursive tree walker function.
So, yes, remove the existing dead&confusing option and method, and then (independently) consider adding method="c14n2" as a new feature, duplicating the C14N serialisation options with_comments and strip_text to ET.write() and tostring(). (Or, which might be a more general feature, allow serialising to a parser Target object.)
gh-118318: Remove outdated c14n references from ElementTree (GH-118319)
pythongh-118318: Remove outdated c14n references from ElementTree (py…