knile
knile

Reputation: 336

Accept Insertion and reject deletion openxml

I need to compare two Word files and merge all insertions into a third one. I have managed to do that with OpenXML-Power-Tools and WmlCompare, but how do I reject only deletions?

Accepting insertions is easy with OpenXmlPowerTools.RevisionAccepter but I can't get the rejection of deletions to work, that way I would get merged file without revisions.

Should I take this approach or would you suggest different approach?

Rules are:

Upvotes: 1

Views: 216

Answers (1)

Thomas Barnekow
Thomas Barnekow

Reputation: 2259

It is relatively easy to reject, or undo, deletions. So, say you have the following sample paragraph with one w:del element that wraps a deleted w:r element.

<w:p>
  <w:r>
    <w:t xml:space="preserve">This is </w:t>
  </w:r>
  <w:del w:id="0" w:author="Thomas Barnekow" w:date="2020-02-16T14:37:00Z">
    <w:r>
      <w:delText xml:space="preserve">deleted </w:delText>
    </w:r>
  </w:del>
  <w:r>
    <w:t>text.</w:t>
  </w:r>
</w:p>

To reject the deletion, you need to unwrap the deleted w:r and turn the w:delText into a w:t again. Without any further processing (see below), the result of your rejecting the deletion would look like this:

<w:p>
  <w:r>
    <w:t xml:space="preserve">This is </w:t>
  </w:r>
  <w:r>
    <w:t xml:space="preserve">deleted </w:delText>
  </w:r>
  <w:r>
    <w:t>text.</w:t>
  </w:r>
</w:p>

As an optional step, using the MarkupSimplifier of the Open XML PowerTools, you could also coalesce adjacent runs having identical formatting, which would result in the following markup:

<w:p>
  <w:r>
    <w:t>This is deleted text.</w:t>
  </w:r>
</w:p>

Upvotes: 3

Related Questions