简体   繁体   中英

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:

  • 1) Text can be added anywhere in the file.
  • 2) Text is always added to file, never deleted.
  • 3) Files have a.docx file extension

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM