How to merge two or more Word 2003 or Word 2007 XML documents into one Word 2007 XML document.

Here are the steps to merge the documents.

Step 1:

Open a new Microsoft Word 2007 document and type

A
B
C

clip_image002

Save the document to C:\Source.xml. Please change the “Save As Type” to “Word XML Document”.

Step 2:

Open a new Microsoft Word 2007 document and type

D
E
F

clip_image004

Save the document to C:\ Destination.xml. Please change the “Save As Type” to “Word XML Document”.

Step 3:

Open Source.xml in Visual Studio and add a package part to hold the content to be merged. Please note that content type is being used i.e. application/xml.

<pkg:part pkg:name="/word/embed/destination.xml" pkg:contentType="application/xml">

    <pkg:xmlData>

    </pkg:xmlData>

</pkg:part>

Step 4:

In Source.xml, add a relationship in document.xml.rels section.

<Relationship Id="afChunkId1" Type="https://schemas.openxmlformats.org/officeDocument/2006/relationships/aFChunk" Target="/word/embed/destination.xml"/>

Please note that value of the Target attribute should be the same as specified in step 3 for pkg:name attribute.

Step 5:

Please specify the following element in document.xml. This element should appear where you would like to see the merged data.

<w:altChunk r:id="afChunkId1" xmlns:r="https://schemas.openxmlformats.org/officeDocument/2006/relationships"/>

Step 6:  

Now open  destination.xml, copy everything except the processing instructions and paste in between <pkg:xmlData> element specified in step 3 in Source.xml.  Please note that you can also merge the Word 2003 XML document by just copying the XML except the processing instructions and pasting in between <pkg:xmlData> element.

Step 7:  

Save Source.xml and open it in Word and you will see that data is merged.

clip_image006

Reference Links
=========================

The following link explains as how Altchunk element can be used to merge the Open XML documents using Open XML SDK.