Click here to Skip to main content
15,867,704 members
Articles / Programming Languages / C#
Article

XML Namespace Shell Extension

Rate me:
Please Sign up or sign in to vote.
3.80/5 (3 votes)
23 Aug 20042 min read 43K   282   23   2
A shell extension to associate applications with particular XML namespaces.

Sample Image - XmlNamespaceShell.png

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:

  1. It is not extensible.
  2. 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:

  1. Intercept the shell invoke on XML documents.
  2. Read the root element of the XML to determine the namespace.
  3. Determine which application to open.
  4. 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.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralWhat's wrong of Pin
Anonymous24-Aug-04 8:03
Anonymous24-Aug-04 8:03 
GeneralRe: What's wrong of Pin
Colin Savage24-Aug-04 8:55
Colin Savage24-Aug-04 8:55 
With hundreds of files with .xml file extension, but with xml content in different xml namespaces, some content is more suitable to a particular editor or viewer.

Perhaps this link will help to understand xml namespaces? http://www.w3.org/TR/1999/REC-xml-names-19990114/

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.