
Adding Text and XML to the Document
In this step, you will create a memorandum, add text to the document, and map XML elements to portions of the document.
To add text to your document
-
Right click ThisDocument in Solution Explorer, and select View Designer.
-
Add the following text to your Word document:
MEMORANDUM
To:
From:
Subject:
The following table lists the contact information you requested:
| Name | Address | City | State | Postal Code |
| Nancy Davolio | 507 - 20th Ave. E., Apt. 2A | Seattle | WA | 98122 |
Next, you will map XML elements to the text within the memorandum. An XMLNode control is created for each XML element that you map. The XMLNode control is named by appending the parent and child element names to the word Node. For example, if you map the Insert element from the schema above, it is named SampleInsertNode. For more information on controls, see Host Items and Host Controls Overview.
To attach the schema to your document
-
On the Tools menu, point to Microsoft Office Word Tools, and select Templates and Add-Ins.
-
In the Templates and Add-ins dialog box, click the XML Schema tab, and click Add Schema.
-
Browse to the ActionsPaneSample.xsd schema you created earlier, which is located in your project directory, and click Open.
-
Click OK in the Schema Settings dialog box.
-
Click OK to close the Templates and Add-ins dialog box.
The XML Structure task pane opens.
To map XML elements to your document
-
Click the Sample element in the XML Structure task pane.
-
Click Apply to Entire Document when prompted.
-
Select the three lines of text that contains To, From, and Subject, and click the Insert element in the XML Structure task pane.
-
Place your cursor after To:, press the TAB key twice, and click the MemoTo element to insert it.
-
Place your cursor after From:, press the TAB key twice, and click the MemoFrom element.
-
Place your cursor after Subject:, press the TAB key once, and click the MemoSubject element.
-
Select the table so that the entire table is highlighted, and click the Table element to apply it.
The XML tags appear within the table cells.
-
Clear the Show XML tags in the document check box.
-
Click XML Options at the bottom of the XML Structure task pane.
-
Select the Ignore mixed content check box, and click OK.
-
Close the XML Structure task pane.