With the document mapped to our XML schema, let's save this document to XML conforming to the book order schema we have used. First, make sure you save your document as a .doc file so that you do not lose your work. After you have saved the document, from the File menu choose the Save As command. From the Save as type drop-down list, choose XML Document. Two check boxes appear in the dialog: Apply transform and Save data only. Make sure the Save data only check box is checked, as shown in Figure 22-23. Then Click the Save button. Word will warn you that it is only going to save out XML and not any formatting. If you have already saved your document as a .doc file, click the Continue button to save as XML. When you open the saved XML, it will look like Listing 22-1.
Figure 22-23. Saving as an XML document with Save data only checked.
There are some other ways to save to XML that will not generate our book order XML. If save data only is not checked, Word will save the document in an XML format called WordprocessingML, or WordML for short. WordML is an XML file format that Word documents can be saved in that preserves all the formatting and features of a Word document. If you look at the WordML XML file that is generated for this example, you will notice that the WordML schema is used to represent Word content. The book order schema is also used in the saved WordML document to mark up any content that we schema mapped. In the snippet of the WordML file shown in Listing 22-4, you can see that the WordML file format uses the CustomerName element to mark up the customer name (John Doe), but what is marked up is the WordML representation of the customer name rather than just the simple text John Doe.
Listing 22-4. A Snippet of WordML Representing the Customer Name Label and XML Mapped CustomerName
Customer Name: John Doe
You can also use a transform when saving by checking the Apply transform box. A transform is an XSLT file that acts on the WordML XML file and transforms it to some other XML format. For example, you could create an XSLT transform that takes a WordML XML file and transforms it to XML conforming to the book order schema. This does not seem necessary because clicking the Save data only option already does this. There are compelling scenarios around a similar scenario: importing XML data and applying a transform to convert it to a nicely formatted document in WordML. The next section examines this scenario in more detail.
Part One. An Introduction to VSTO
An Introduction to Office Programming
Introduction to Office Solutions
Part Two. Office Programming in .NET
Working with Excel Events
Working with Excel Objects
Working with Word Events
Working with Word Objects
Working with Outlook Events
Working with Outlook Objects
Introduction to InfoPath
Part Three. Office Programming in VSTO
The VSTO Programming Model
Using Windows Forms in VSTO
Working with Actions Pane
Working with Smart Tags in VSTO
VSTO Data Programming
Server Data Scenarios
.NET Code Security
Part Four. Advanced Office Programming
Working with XML in Excel
Working with XML in Word
Developing COM Add-Ins for Word and Excel
Creating Outlook Add-Ins with VSTO