Introduction
This utility allows you to associate a different editor with an XML namespace, while keeping your existing file associations intact.
Background
If you have ever used the Microsoft Office 2003 Save as XML feature in Word or Excel, you will have seen that although the file has a .xml file extension, it still opens with the appropriate Office application. Digging a little deeper, you will see that there is a processing instruction <?mso-application progid="Word.Document"?> in the XML file that the Office shell extension reads, to determine which application to open.
Although this is a cool feature, it is a bit limited because:
- It is not extensible.
- If it was extensible, you would need to modify your existing XML documents to include a processing instruction.
With these problems in mind, I started looking for some code to:
- Intercept the shell invoke on XML documents.
- Read the root element of the XML to determine the namespace.
- Determine which application to open.
- If the namespace has no application associated, default to the original file extension handler.
I found the Creating a shell extension with C# article by Richard Birkby which is almost a perfect fit for the shell extension I needed. I have also used the isolated storage class from Persisting Application data using HashTable and IsolatedStorage by T Manjaly for storing the associations per user.
Using the code
The bulk of the code is best explained by the two excellent articles referenced above.
The application consists of an exe and a DLL. The exe is used to install and uninstall the shell extension (the DLL), and to add and remove namespaces. Once the extension is installed, you can use the menu to add and remove namespaces on the fly without needing to uninstall.
Using the example in the screenshot above, any XML documents that have http://www.w3.org/1999/XSL/Format as the namespace on their root element, will open with Notepad.exe.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.