Mechanism for opening Office .xml Documents
For Word documents saved in XML and having an .xml extensions Microsoft implemented a special handler to open these files in the corresponding application (This mechanism is not only used for Word documents, but also Excel spreadsheets, InfoPath forms and some other formats).
If you check the Registry you will see that the file type for files with a .xml extension is set to xmlfile
:
HKEY_CLASSES_ROOT\.xml (Default) = "xmlfile"
The command that is executed when this file type is opened is specified under
HKEY_CLASSES_ROOT\xmlfile\shell\open\command = ""C:\Program Files\Common Files\Microsoft Shared\OFFICE12\MSOXMLED.EXE" /verb open "%1""
So when an XML file is double-clicked in Explorer, Windows will launch MSOXMLED.EXE. This application is now looking inside the XML file and searches for an XML processing instruction. This processing instruction named mso-application can specify a ProgId:
<?mso-application progid="Word.Document"?>
If this processing instruction is found and the ProgId is one of the supported values MSOXMLED.EXE searches the Registry for the open command specified for that ProgId. For Word.Document there is actually another redirect to Word.Document12 (if Office 2007 is installed) using the CurVer subkey of Word.Document, so we end up with:
HKEY_CLASSES_ROOT\Word.Document.12\shell\Open\command = ""C:\Program Files\Microsoft Office\Office12\WINWORD.EXE" /n /dde"
So finally MSOXMLED.EXE will start the appropriate Office application or launch the default XML application which is specified under
HKEY_CLASSES_ROOT\XEV.GenericApp\shell\open\command
You can actually try this out by calling MSOXMLED.EXE from the command line:
MSOXMLED.EXE /verb OPEN "SampleWordMLDocument.xml"
If you would like to implement the same behavior you would have to implement a handler like MSOXMLED.EXE which looks inside the file for a pre-defined processing instruction and then routes the document to the appropriate application.
Icon handling
Above we looked at the way how document opening and editing is handled. Another mechanism is responsible for displaying a specific icon depending on the processing instruction inside the XML document: an icon handler.
Icon handlers are a type of Explorer Shell extensions which are in-process COM objects which can be associated with certain file types. The one used for XML files is specified in the Registry under
HKEY_CLASSES_ROOT\xmlfile\ShellEx\IconHandler = "{AB968F1E-E20B-403A-9EB8-72EB0EB6797E}"
This GUID is refering to the MSOXEV.dll which will - similarly to MSOXMLEX.EXE inspect the XML file for the ProgId and then provide the correct icon.
As all this is a rather complicated mechanism you should consider carefully if you want to go this way. In my opinion it is far simpler to register a new unique file extension. It is also limited as it will only work with file types that allow you to include some custom information (as the ProgId) in the header of file.
Microsoft does not use this method anymore and uses file extensions instead for their new OpenXML formats (see Why do Office ".xml" files behave differently from other ".xml" files?).