openpyxl.preserve.lexical
paper-xlsx 0.2.1 API reference
Patch modeled XML changes without reserializing unchanged syntax.
The preserve writer compares a settled model serialization from load time with the current serialization. When both have the same element shape, this module transfers only the changed attribute values and leaf text into the original bytes. Attribute order, quote style, omitted defaults, namespace spelling, whitespace, and unknown children therefore remain untouched.
patch_xml
funcpatch_xml(original, baseline, current, expected_root)Return original with only model-observed lexical deltas applied.
None means the edit changed element shape or could not be mapped
unambiguously. Callers may then use a guarded structural fallback, but
must not silently normalize XML that carries unowned content.
paramoriginalbytesOriginal XML bytes to preserve.
parambaselinebytesModel serialization captured before editing.
paramcurrentbytesModel serialization after editing.
paramexpected_rootstrExpected local name of the XML root element.
Returns
bytes | NonePatched XML bytes, or None when a safe patch is unavailable.