XML Editor in VS2005: Schema Cache and Schema Catalogs

Below are a few tips and tricks on using schema cache and schema catalogs with the new XML Editor in VS 2005.

Schema Cache

The XML Editor comes with a set of schemas that describe some of the W3C standard and some of the VS specific XML namespaces.  These schemas are installed into your VS installation directory under %vsinstalldir%\xml\schemas.  When you declare one of the namespacess defined by these schemas in your XML files, the XML Editor will automatically associate appropriate schema(s) from the cache location and instantly provide you with intellisense data and validation.  The purpose of the schema cache directory is to hold standard schemas as well as schemas that are unlikely to change.

The following operations are supported by the XML Editor without requiring a VS restart.
- Adding schemas
- Deleting schemas
- Renaming schemas

You can also change the schema cache location.  This is done by modifying Cache Directory Location on Tools | Options | Text Editor | XML | Miscellaneous dialog.  When you do this, the XML Editor will stop using schemas from the old location and instead switch to the new folder.

Schema Catalogs

You can extend existing schema cache using catalog.xml file.  VS installs a sample catalog.xml file (along with catalog.xsd) in the schema cache folder.  This file can be used to do several things.  First of all, you can associate namespaces with external locations as in the following example:

<

Schema href="%VsInstallDir%/Common7/IDE/Policy/Schemas/TDLSchema.xsd"

   targetNamespace="https://www.microsoft.com/schema/EnterpriseTemplates/TDLSchema"/>

You can also associate file extensions with specific namespaces.  The following line taken from the sample catalog.xml associates .config files with dotNetConfig.xsd schema

<

Association extension="config" schema="%VsInstallDir%/xml/schemas/dotNetConfig.xsd"/>

Finally, you can point your catalog to another catalog file creating a chain:

<

Catalog href="https://mycompany/catalog.xml"/>