The first thing to note about the XML features described in this chapter is that most of them are only available in Microsoft Office Professional Edition 2003 and the standalone version of Microsoft Office Word 2003. If you work with other Office Editions such as Microsoft Office Standard Edition 2003, Microsoft Office Student and Teacher Edition 2003, or Microsoft Office Basic Edition 2003, the XML features described in this chapter are not available.
Many of the XML features of Word are accessed via Word's XML Structure task pane. To show the XML Structure task pane, display the task pane if it is not already displayed by choosing Task Pane in Word's View menu. The task pane has a drop-down menu from which the XML Structure task pane can be selected, as shown in Figure 22-1.
Figure 22-1. Selecting the XML Structure task pane from the task pane drop-down menu.
The XML Structure task pane prompts you to go to the Templates and Add-Ins dialog to attach an XML schema to the document. To get to the Templates and Add-Ins dialog, you can click the Templates and Add-Ins hyperlink shown in the task pane in Figure 22-2 or choose Templates and Add-Ins from the Tools menu and then click the XML Schema tab.
Figure 22-2. The XML Structure task pane prompts you to go to the Templates and Add-Ins dialog to add an XML schema.
Figure 22-3 shows the Templates and Add-Ins dialog. This dialog shows available XML schemas that can be attached to the Word document by checking the check box next to an available schema. It also provides a button to add a new schema to the document.
Figure 22-3. The Templates and Add-Ins dialog with the XML Schema page selected.
To add a new schema to the document, click the Add Schema button. When you click the Add Schema button, you are prompted to browse to the schema file you want to add to the document. Let's use the book order schema we created in Chapter 21, "Working with XML in Excel." After you select the schema, the Schema Settings dialog appears, as shown in Figure 22-4. Let's enter BookOrder as an alias or friendly name for the book order schema.
Figure 22-4. Picking an alias for a newly added schema in the Schema Settings dialog.
Click OK to dismiss the Schema Settings dialog. Doing so returns you to the Templates and Add-Ins dialog. The book order schema has been added, as shown in Figure 22-5, and is attached to the current document as shown by the checked check box next to the BookOrder schema. The BookOrder schema can be detached from the document by unchecking the check box.
Figure 22-5. The BookOrder schema has been attached to the Word document.
Now that the BookOrder schema has been added, it will be available for attachment to other documents because Word automatically adds any added schemas to Word's schema library. To manage Word's schema library, click the Schema Library button in the Templates and Add-Ins dialog. The Schema Library dialog appears, as shown in Figure 22-6. This dialog provides the same Add Schema button that lets you add new schemas. It also can edit the schema settings dialog for an already added schemafor example, you can select a schema and click the Schema Settings button to assign the book order schema a different friendly name. A Delete Schema button lets you delete a schema from the schema library.
Figure 22-6. The Schema Library dialog.
The bottom half of the Schema Library dialog provides options to associate smart document solutions with a document to which a particular schema is attached. In this book, we do not cover this part of Word's functionality because VSTO 2005 provides an easier way to build Word solutions through the ActionsPane mechanism described in Chapter 15, "Working with Actions Pane." However, we do cover the ability to use the Solutions section to associate an XSLT file with a particular schema.
When you close the Schema Library dialog and the Templates and Add-Ins dialog, the XML Structure pane is updated to show elements from the book order schema, as shown in Figure 22-7. With the book order schema attached to the document, you are now ready to start applying XML elements to the document.
Figure 22-7. The XML Structure dialog with the book order schema attached to the document.