Paper Office
paper-xlsxAPI referencepreserve.lexical

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.

paramoriginalbytes

Original XML bytes to preserve.

parambaselinebytes

Model serialization captured before editing.

paramcurrentbytes

Model serialization after editing.

paramexpected_rootstr

Expected local name of the XML root element.

Returns

bytes | None

Patched XML bytes, or None when a safe patch is unavailable.

On this page