Once the tool is installed (see
for details on the installation process), you can use it to create structured Word documents, using XML parts and mapped content controls.
This introduction will walk you through a simple scenario which demonstrates how the tool can be used.
In this example, we’ll create an XML part that contains all of the header information that we need to extract from a memo template (e.g. the customer’s name), which we could then shred into a SQL database, submit to a web service, etc.
Step 1: Create the XML part
The first step to creating this solution is to define the XML structure of the data we want to capture from the document.
- Copy the memo template to your PC:
- Copy the following XML file to your PC:
data.xml. This file contains the following XML:
- A memo element, at the root of the XML document
- A to element to store the customer's name
- A from element to store the sender's name
- A subject element to store the subject of the memo
- A date element to store the date of the memo
- A CC element, to store any names on the CC: line of the memo
- A body element, to store the text of the memo itself
- Open the memo template in Word 2007 or 2010
- Open the XML Mapping task pane by clicking on the XML Mapping button on the
Mapping group of the Developer tab
- Click on the XML Part drop-down list
- Choose Add New Part...
- In the dialog box, choose Copy the contents of an existing XML file to create the part, since we already have the XML for the part
- Choose Next...'
- Choose Browse... and locate the XML file from Step 2 above
- Choose Finish
At this point, Word will copy the XML from the file into a new XML part in the document. The original XML file is not deleted, but Word now has its own copy of the data stored in the Open XML document.
The task pane also refreshes to show the XML contents of the new part:
Step 2: Insert Mapped Content Controls
Once the XML part has been added to the document, we can now add mapped content controls to the page. Each of these content controls, when edited, will store its text in a node in the XML part.
First, we'll do the header items via right-click:
- Place your cursor next to the To: line in the template
- Right-click on the to element in the task pane's tree view
- Choose Insert Content Control
- Choose Text
This will insert a content control mapped to the to
You can then repeat this for the from
elements, inserting text content controls next to each of the corresponding headings.
For the date
element, we can insert a date content control:
- Place your cursor next to the Date: line in the template
- Right-click on the date element in the task pane's tree view
- Choose Insert Content Control
- Choose Date
Now, the header should have a content control on each line:
Finally, we can insert a mapped content control for the body
element via drag and drop:
- Click on the body element
- Drag it into the body of the memo (below the dividing line)
- Drop it
At this point, all of the data we want to store in our XML part is mapped to content controls in the document.
Step 3: Try it out!
Now that the template is set up, we can try it out:
- Save the document
- Type content into each of the content controls
- Use Save As to save a new copy with your data
- Close Word
- Rename the file extension to ZIP
- In the customXml folder, examine the item1.xml file
This file contains the values of each of the mapped content controls in the document, seperated from the formatting. You can then extract this file to shred into a SQL database, submit to a web service, etc.