Skip to content

Remove outdated method='c14n' references from ElementTree #118318

Closed

Description

@danifus

Feature or enhancement

Proposal:

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

Links to previous discussion of this feature:

No response

Linked PRs

Activity

  1. danielquinn commented on Apr 21, 2025

    @danielquinn

    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.

  2. serhiy-storchaka commented on May 24, 2026

    @serhiy-storchaka
    Member

    @scoder, what are your thoughts?

  3. added
    stdlibStandard Library Python modules in the Lib/ directory
    on May 24, 2026
  4. scoder commented on May 24, 2026

    @scoder
    Contributor

    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.)

  5. added a commit that references this issue on Aug 9, 2026
  6. added a commit that references this issue on Aug 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.16new features, bugs and security fixesstdlibStandard Library Python modules in the Lib/ directorytopic-XMLtype-featureA feature request or enhancement

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions