Accept all revisions in a word processing document
Tracked revisions are stored as WordprocessingML markup in the main document and supporting parts. Accepting revisions means transforming inserted, deleted, moved, and property-change markup into the final accepted content.
The document structure still follows the normal WordprocessingML hierarchy: document, body, paragraphs (p), runs (r), and text (t). Revision elements wrap or annotate that content and must be resolved without breaking the surrounding paragraph, run, and table structure.
Revision markup
Common revision elements include:
| Element | Meaning when accepting |
|---|---|
<w:pPrChange/> | Keep the current paragraph properties and remove the tracked previous state. |
<w:del/> | Remove deleted content or paragraph mark revision metadata, depending on where it appears. |
<w:ins/> | Keep inserted content and remove insertion metadata. |
<w:moveFrom/> / ranges | Remove the move source content. |
<w:moveTo/> / ranges | Keep the move destination content and remove move metadata. |
In ooxmlsdk, generated schema types for these elements include ParagraphPropertiesChange, Deleted, Inserted, MoveFrom, MoveTo, MoveFromRangeStart, MoveFromRangeEnd, MoveToRangeStart, and MoveToRangeEnd.
Rust workflow
Accept common revision markup in the main document XML:
#![allow(unused)] fn main() { pub fn accept_common_revisions(path: &Path) -> Result<Vec<u8>, Box<dyn std::error::Error>> { let mut document = WordprocessingDocument::new_from_file_with_settings(path, lazy_settings())?; let main_part = document.main_document_part()?; let document_xml = main_part.data_as_str(&document)?.unwrap_or_default(); let updated_xml = accept_revision_markup(document_xml); main_part.set_data(&mut document, updated_xml.into_bytes())?; let mut buffer = Cursor::new(Vec::new()); document.save(&mut buffer)?; Ok(buffer.into_inner()) } }
Do not treat revision acceptance as a simple string replacement. Some revisions live in paragraph properties, table row properties, run content, comments, headers, footers, footnotes, or endnotes. Apply the same acceptance rules to every story that can contain tracked changes when you need whole-document acceptance.