The ElementTree class in the Python xml.etree
API has a write()
method that documents the optional method
argument:
*method* -- either "xml" (default), "html, "text", or "c14n"
At least with Python 3.5 (on Fedora 25) writing with this method
import xml.etree.ElementTree as ET
# ... create some elements ...
tree = ET.ElementTree(root)
tree.write(filename, method='c14n')
just throws a ValueError:
File "/usr/lib64/python3.5/xml/etree/ElementTree.py", line 751, in write
raise ValueError("unknown method %r" % method)
ValueError: unknown method 'c14n'
And the ElementTree code contains this note:
_serialize = {
"xml": _serialize_xml,
"html": _serialize_html,
"text": _serialize_text,
# this optional method is imported at the end of the module
# "c14n": _serialize_c14n,
}
What is that supposed to mean, exactly?
How to serialize a ElementTree to a c14n XML file in Python?