Hack 91 Create a Word Document in Notepad![]() ![]() XML files to create Word documents.If you save one of your Word documentseven a very simple one with just a line or two of textin XML format, then open it in a standard text editor such as Notepad, you'll see that the file contains much more than just the text you typed.Fortunately, Word can fill in most of that information if it's missing, so you don't need to be quite so verbose when creating XML documents meant to be opened in Word.For example, open Notepad or another standard text editor and type the following: <?xml version="1.0"?>The w:body element contains the body of the document; the w:p element stands for "paragraph," the w:r element stands for "run," and the w:t element contains text in the document.Now save the file as Hello.xml. If you look at the file in Windows Explorer (or from Notepad's Save As dialog box), you'll see that it has a special icona combination of the icon used for XML files and the icon used for Word documents, as shown in Figure 10-3. Figure 10-3. Windows recognizes the file as an XML file meant for Word![]() rather than your default XML viewer (usually Internet Explorer). Figure 10-4 shows the Hello.xml document after Word has opened it. If you save the file from within Word, then open it in Notepad, you'll see that Word has added quite a bit of additional information (check out Figure 10-6 in [Hack #92] to see the information Word inserts). Figure 10-4. Your XML document opens in Word![]() whatever program usually opens XML files on your system), is the following line included in the file: <?mso-application prog?>This processing instruction (PI) associates the XML document with Word. It is also used for other applications in Microsoft Office: the progid pseudoattribute can have Excel.Sheet and InfoPath.Document as values, for example.As you can see, there's nothing fancy here; Word used the Normal paragraph style to provide all the formatting information. However, this simple example shows how you can use plain text to create fully functional Word documents. See [Hack #94] for a more detailed example of using XML to create Word documents.Evan Lenz |