How to add a custom intellisense and validation schema to Visual Web Developer 2005

Let's imagine that you want to add Internet Explorer 7 schema. Here what you need to do

1. Copy Program Files\VS8\Common7\Packages\Schemas\HTML\ie6_0.xsd to ie7_0.xsd.

2. Open ie7_0.xsd in VS XML editor: (File | Open | click small arrow on the Open button,

choose XML Editor) or any other text editor.

3. In the root xsd:schema element change namespace URI from IE6 to IE7, CSS schema to CSS 2.1 and change friendly name to Internet Explorer 7:

<xsd:schema version="1.0"
targetNamespace='https://schemas.microsoft.com/intellisense/ie7'
xmlns='https://schemas.microsoft.com/intellisense/ie7'
xmlns:xsd='https://www.w3.org/2001/XMLSchema'
xmlns:vs='https://schemas.microsoft.com/Visual-Studio-Intellisense'
vs:clientom="ie6_0dom.tlb"
vs:ishtmlschema="true"
vs:isserverschema="false"
vs:htmlflavor="4.0"
vs:MultipleScriptLanguages="true"
vs:cssschema="CSS 2.1"
vs:SuccinctFriendlyName="Internet Explorer 7">

You can leave reference to to DOM (vs:clientom attribute) unchanged as we are not changing anything in the DOM (which drive client script intellisense) at this time. If you are interested in how to change the DOM, have a look at my earlier blog posts: Part 1 and Part 2.

4. Save the file and exit Visual Studio.

5. Create a registry script to add your schema to the list of the HTML editor validation and intellisense schemas.

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\8.0\Packages\{1B437D20-F8FE-11D2-A6AE-00104BCC7269}\Schemas\Schema 21]
"Friendly Name"="Internet Explorer 7.0"
"URI"="https://schemas.microsoft.com/intellisense/ie7"
"File"="html\\ie7_0.xsd"

Note that here I hardcoded Schema 21 since I know that Whidbey comes with 20 schemas. You may want to check if that is true on your machine: some add-ins may install extra schemas. There should not be any gaps in numbering or your new schema won't be loaded.

7. Run the registry script (you will need admin rights), start VS, create a new HTML page and observer new schema appear in the target schema dropdown on the HTML editor toolbar.

You may ask what are those 20 schemas are for and why there are only 7 visible in the target browser dropdown. The reason is that some schemas only apply to certain file types. For example, there is a schema for Global.asax and since this and only this schema applies to this file type, the schema does not have a friendly name and does not appear in the target schema dropdown. In fact, when you open Global.asax, you'll see that target schema dropdown is disabled. The relationship between Global.asax and its schema are hardcoded. Some other schemas are 'companion' schemas. For instance, intellisense and validation on a typical Web Form file (aspx) uses target browser schema, server directives schema as well as schemas dynamically generated from server controls.

Note that in VS 2003 we were picking up all schemas in the schema folder as well as all schemas included in the project. For performance reasons we are no longer sniffing files on VS startup and are no longer monitoring file changes on disk. Therefore, all schemas must appear in the registry and when you are adding a a new schema or changing an existing one, you have restart the IDE.

Comments

  • Anonymous
    February 02, 2006
    Trackback from dotnetkicks.com

  • Anonymous
    February 17, 2006
    Cool tip! I'm trying to track down more documentation on how VS 2005 handles Intellisense XSD's...so most of what I've come across is for VS 2003. Specifically, I'm wondering if there's a way to troubleshoot my XSD or something that explains how VS parses it. (I'm getting validation errors on code that should be valid.) Any suggestions?

    - Orion

  • Anonymous
    February 18, 2006
    VS 2005 parses intellisense schema XSD close to what VS 2003 did. What kind of errors are you getting?

  • Anonymous
    May 10, 2006
    I've posted another new DevNugget to Channel 9. This one focuses on the schema-driven Intellisense and...

  • Anonymous
    May 10, 2006
    In this DevNugget, .net Developer Evangelist G. Andrew Duthie (aka .net DEvHammer), shows you how you...

  • Anonymous
    February 16, 2007
    A few months ago I was working on a project that required the creation of full schemas for the configuration

  • Anonymous
    June 16, 2007
    One cool new feature available in Visual Studio 2005 is the ability to take advantage of Intellisense statement completion in the Source view of an ASP.NET Web Form. In addition, Visual Studio 2005 provides validation of your markup.

  • Anonymous
    June 17, 2007
    Whenever I start a new web project, one of the first things I do is create a "Base" class for all my...

  • Anonymous
    October 19, 2007
    PingBack from http://msdnrss.thecoderblogs.com/2007/10/19/how-to-create-custom-css-intellisense-schema-in-visual-studio-2005-and-2008/

  • Anonymous
    January 23, 2008
    PingBack from http://leaco.blogli.co.il/archives/59

  • Anonymous
    January 17, 2009
    PingBack from http://www.hilpers.it/2615773-convalida-di-vs-w3c-schemas

  • Anonymous
    January 18, 2009
    PingBack from http://www.keyongtech.com/1191373-custom-html-validation-in-vs2005