Word Hacks [Electronic resources]

Andrew Savikas

نسخه متنی -صفحه : 162/ 130
نمايش فراداده

Hack 93 Use IE to Inspect WordprocessingML Documents

Internet Explorer is a great tool for reading WordprocessingML files, but without a little hacking, it's hard to keep Word's hands off those files.

Internet Explorer's default tree-view stylesheet for XML documents provides a handy, readable way to investigate the structure of WordprocessingML documents, as shown in Figure 10-7Figure 10-7. However, if you try opening a WordprocessingML document in Internet Explorer (i.e., right-click the file and select Open WithInternet Explorer), IE turns right around and launches Word. Why? IE recognizes WordprocessingML files as Word documents because of the single-line processing instruction [Hack #91] :

Figure 10-7. A WordprocessingML file viewed in Internet Explorer

<?mso-application prog?>

You can use two techniques to get around this little annoyance.

The first technique simply removes the mso-application line before it opens the WordprocessingML document in IE:

Save the Word document as XML and then close it.

Open the newly saved WordprocessingML document in Notepad.

Delete the line with the mso-application processing instruction and resave the file.

Internet Explorer will now display the document using its pretty XML tree view, even if Word subsequently updates the document to include the mso-application PI. Once it's been opened in IE, you can refresh IE to see how changes to the document from within Word affect the underlying WordprocessingML.

The second technique involves making a temporary change in your Windows registry, obviating the need to remove the mso-application line from each and every document you want to inspect:

Select StartRun and type regedit to open the registry editor.

Find the subkey named HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\11.0\Common\Filter\text/xml.

Right-click the Word.Document string value entry and select Rename.

Change the name to something like Word.DocumentDISABLED.

The Windows registry stores important system information. Before making any changes to the registry, set a system restore point by choosing StartAll ProgramsAccessoriesSystem ToolsSystem Restore (the exact location may be different on your system).

To restore the setting later, simply rename it again, removing the "DISABLED" part. Figure 10-8 shows the registry editor and the applicable entry being renamed.

Figure 10-8. Getting around IE's refusal to render the XML source of WordprocessingML documents

With the WordprocessingML filter effectively disabled, IE will now open WordprocessingML documents using its default XML tree-view stylesheet. Windows Explorer, however, will still continue to associate WordprocessingML documents with Word (if you double-click a WordprocessingML file, you will always launch Word), which is probably what you want anyway.

Evan Lenz