Andrew Connell [MVP MOSS]
1468 Posts |  40 Articles |  0 Comments
.NET  |  MCMS  |  SharePoint  |  Office System
SharePoint Quick Links
Article Categories
Archives
Post Categories


Add to Technorati Favorites

First, this process will work for any XML schema file, not just SharePoint files. I'm just using SharePoint as the case in this example.

All XML files, or just about every XML file I've run across so far, in Windows SharePoint Services (WSS) v3 & Mirosoft Office SharePoint Server (MOSS) 2007 is validated by SharePoint using the WSS schema file found in the 12 hive: %12HIVE%/TEMPLATES/XML/wss.xsd.

What's that %12HIVE%? It's a variable I add to my SharePoint environments making it easier to change directory to the 12 hive when I'm in a command prompt. I explained how to add this, along with other tips, in my SharePoint developer tips and tricks post.

Unfortunately the schema is wildly inconsistant (at least in Beta 2 Technical Refresh). For example, the <Feature> node expects an attribute Id, but the <Field> node expects the same attribute as ID (notice the capitalization of 'D' in both). Arg... what a PITA! Obviously intellisense would be a huge help in avoiding these minor syntax issues that will cause SharePoint to choke when validating the XML.

Adding an XML Schema To a Specific File In Visual Studio 2005
I think it is fairly common knowledge to most developers that you can specify an XML schema for a specific file in Visual Studio. To do this, when you have the XML file open, go to the Properties toolpane and click on the ellipses for the Schema field (see Figure 1), select the Add button in the XSD Schemas dialog, browse to the wss.xsd file in the 12 hive (location listed above) and OK out of the dialogs.

XmlSchemaCache_PropertyToolPane
Figure 1 - XSD Schema field in the Properties toolpane when the active open file is of type XML

Now, if you go back to your XML file, enter a top-level node that's used in SharePoint v3 (such as <Feature>)you'll start to see intellisense in your XML files (see Figure 2)! Visual Studio will even add the SharePoint namespace... very slick!

XmlSchemaCache_Intellisense
Figure 2 - XML intellisense in action for SharePoint XML files!

There's only one downside to doing it this way: you have to add the wss.xsd file to every single XML file you're working with... and that's tedious. There must be a better way... ah... entering from stage-right: the Visual Studio XML Schema Cache!

Adding the WSS.XSD SharePoint XML Schema to the Visual Studio 2005 XML Schema Cache
First, this is fully documented in the MSDN documentation, so feel free to try this at home. You can tell Visual Studio 2005 to load the WSS.XSD SharePoint XML schema file everytime you create a new XML file. This way, you won't have to do the method detailed above (specifying the WSS.XSD schema for each and every XML file you work with). To do this, you add it to the XML Schema Cache... let me show you how to do this:

First, using Windows Explorer, navigate to [Visual Studio 2005 Installation Directory]\Xml\Schemas, copy the catalog.xml file and give it a new name... I like to use sharepointcatalog.xml. Now, remove all the <Schema> and <Association> nodes from the sharepointcatalog.xml file except for a single <Schema> node... we'll use this one as our template. The <Schema> node takes two attributes: href (the location of the XML schema to load) and targetNamespace (the namespace of the XML schema). You want to replace the values of the only <Schema> node with the location of the WSS.XSD file and the SharePoint namespace. When finished, save your file.

Here's what my complete sharepointcatalog.xml file looks like after making these changes:

   1:  <SchemaCatalog xmlns="http://schemas.microsoft.com/xsd/catalog">
   2:    <Schema href="file://C:/Program Files/Common Files/Microsoft Shared/web server extensions/12/TEMPLATE/XML/wss.xsd" 
   3:            targetNamespace="http://schemas.microsoft.com/sharepoint/"/>
   4:  </SchemaCatalog>

Now, to get this to take effect, you'll need to close and restart Visual Studio. Once you do so, when you create a new XML file, all you have to do is specify the SharePoint XML namespace (using the xmlns attribute) in the root element and you're set! This is easy to do... start typing one of the SharePoint recognized root nodes (such as <Feature>), add the xmlns attribute, trigger intellisense by pressing [CTRL]+[SPACE] and pick the SharePoint namespace from the list of XML Schemas loaded in the Visual Studio XML Schema Cache (see Figure 3).

XmlSchemaCache_FeatureNamespace
Figure 3 - Selecting the SharePoint XML Schema

After closing the <Feature> node, you can now use intellisense for all nodes and attributes in the file as shown in Figure 4. Sweet!

XmlSchemaCache_FeatureChildNodes
Figure 4 - Intellisense in action with the SharePoint XML Schema!

» AC's SharePoint developer tips & tricks
» MSDN: Schema Cache 

[Updated 2/17/2009 @ 5p] : For even better IntelliSense (including Visual Studio 2008), check this out.

 

 

 

posted on Friday, October 20, 2006 5:11 PM

Feedback

# SharePoint resources 2/21/2007 9:45 AM Stefan Go&#223;ner
WSS 2.0 Best Practices: Using Disposable Windows SharePoint Services Objects WSS 2.0 SDK Whitepaper -

 re: Adding Intellisense When Editing XML Files in WSS v3 / MOSS 2007 3/22/2007 4:28 PM Rob Edwards
Gravatar For some reason, it's not working for me. Does it require Sharepoint DLL's somewhere? I am trying to do this on an XP box.

# re: Adding Intellisense When Editing XML Files in WSS v3 / MOSS 2007 3/22/2007 4:35 PM AC [MVP MOSS]
Gravatar Rob-
Make sure you (1) include the trailing "/" in the shcema within the catalog and (2) you close & restart Visual Studio as the cache is loaded only when VS2005 starts up and (3) you copied WSS.XSD over to your XP box. It doesn't require the DLL anywhere... just requires that the catalog is pointing to an existing WSS.XSD (if you are doing this on WinXP and you haven't copied over WSS.XSD, then that's your error.

 re: Adding Intellisense When Editing XML Files in WSS v3 / MOSS 2007 5/14/2007 1:27 PM Trinh
Gravatar Excellent presentation.
Thank you very much

 re: Adding Intellisense When Editing XML Files in WSS v3 / MOSS 2007 7/27/2007 11:45 AM Matthew McDermott
Gravatar Andrew, Thanks so much for this post! If you are using the *.xsd files locally you just need to include all the supporting files from the XML directory. Copy wss.xsd, CamlView.xsd, CamlQuery.xsd, CoreDefinitions.xsd. The catalog file still only references wss.xsd.

THANKS!

# re: Adding Intellisense When Editing XML Files in WSS v3 / MOSS 2007 7/31/2007 5:10 PM randy
Gravatar wow, that was a total PITA until I read the last comment.

that made it work for me.

ty ty Matthew!

 re: Adding Intellisense When Editing XML Files in WSS v3 / MOSS 2007 10/26/2007 9:24 AM Vadim Sacharow
Thank you, man!

 re: Adding Intellisense When Editing XML Files in WSS v3 / MOSS 2007 2/22/2008 9:14 AM Simon
Hi, has anyone got this working in VS 2008?

# re: Adding Intellisense When Editing XML Files in WSS v3 / MOSS 2007 2/22/2008 9:19 AM AC [MVP MOSS]
Gravatar Simon-
Yup... you need to copy the XML file to the it to the VS 2008 XML Schema Cache: C:\Program Files\Microsoft Visual Studio 9.0\Xml\Schemas

 Works with VS 2008 5/27/2008 7:15 AM Islam Eldemery
I copied the wss.xsd schema file to
C:\Program Files\Microsoft Visual Studio 9.0\Xml\Schemas
and my xml file automatically associated with this schema..
but the intellesense didn't work..
So I removed the reference and added a new one referencing the original file in this location
C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\XML
and it works fine

# re: Adding Intellisense When Editing XML Files in WSS v3 / MOSS 2007 5/27/2008 8:26 AM AC [MVP MOSS]
Gravatar Islam-
Not sure I understand what you're saying. The method works just fine in both VS2005 & VS2008. The only difference is where you put the catalog.xml file as it's different for each Visual Studio version (due to the fact they are installed in separate directories).

 re: Adding Intellisense When Editing XML Files in WSS v3 / MOSS 2007 8/24/2008 11:07 PM Yangxin
I found the XML Schema Cache is kind of funky. If you played with 2nd method several times (add the xml file and remove it) and restart VS, it works sometimes but sometime it doesn't work.
If it doesn't work, use the 1st method and remove the sechema from Properties dialog window in VS and close VS and try again.


 re: Adding Intellisense When Editing XML Files in WSS v3 / MOSS 2007 9/20/2008 12:20 AM Rajeev
Gravatar Hi Andrew,
Thank you very much, its working for me

 re: Adding Intellisense When Editing XML Files in WSS v3 / MOSS 2007 12/11/2008 8:47 AM Don
Hi Andrew,

I'm trying to use Intellisense with XML files stored in a SharePoint library. The library is on the local network and I have mapped it in Windows. I can open the files in VS and Intellisense works fine; however, I can't save the files to the SharePoint library with VS.

I know SPD is supposed to the tool to use with SharePoint but SPD doesn't support XML intellisense.

Currently I have both VS and SPD open and am copying and pasting between the two but would like a more elegant solution.

Any suggestions?

Thanks,
Don

# re: Adding Intellisense When Editing XML Files in WSS v3 / MOSS 2007 12/11/2008 9:35 AM AC [MVP MOSS]
Gravatar Don-
Unfortunately no... Visual Studio has no understanding of SharePoint an dcan't work directly with it.

 re: Adding Intellisense When Editing XML Files in WSS v3 / MOSS 2007 12/11/2008 10:38 AM Don
Thanks - thought so.

I wonder if VS is deliberately crippled this way to promote SPD? I can open and save files to the SP library with every other application I've tried on my Machine, just not VS.

# re: Adding Intellisense When Editing XML Files in WSS v3 / MOSS 2007 12/11/2008 11:41 AM AC [MVP MOSS]
Gravatar Don-
No, it wasn't deliberatly crippled. VS has been around much longer and it just didn't get the integration pieces that SharePoint needed and SPD has.

 re: Adding Intellisense When Editing XML Files in WSS v3 / MOSS 2007 2/16/2009 1:38 PM Bharat
Gravatar CAML.NET IntelliSense works fine with VS2005 but what to do to get it work on VS2008? I added Schema file in property window while creating a new xml file and adding xmlns reference to sharepoin, but intellisense did not work.
Thank you in advance for your answer.
Bharat

# re: Adding Intellisense When Editing XML Files in WSS v3 / MOSS 2007 2/16/2009 5:07 PM AC [MVP MOSS]
Gravatar Bharat-
Look at this: http://andrewconnell.com/blog/archive/2009/02/15/Getting-even-better-IntelliSense-for-CAML-when-doing-SharePoint-projects.aspx

 re: Adding Intellisense When Editing XML Files in WSS v3 / MOSS 2007 6/5/2009 11:26 AM Amit
Gravatar Hi,

I am using Visual Studio 2008,but is not able to enable this intellisense.
I have tried all sorts of steps mentioned above.

Strangely even Wss.xsd is not working.

I tried installing this on machine having VS 2005.
wss.xsd intellisense is working on this machine,but still CAML.net intellisense is not working.

Any pointers on how to enable it.

regards,
Amit

Post Feedback

Title:
Name:
Email:
(email will not be displayed)
Url:
Comments: 
Please add 4 and 1 and type the answer here:    
All Comments Are Filtered & Moderated
Unfortunately comment spammers are just too effecient and are constantly dirtying up blogs with irrelevant and unwanted comments trying to improve their standing on search engines. All comments on this blog are moderated. I do not censor comments, but I don't approve comments with vulger language or those soliciting products. Most of the time comments are approved within a few hours of being submitted with the only exception when I'm traveling.

Why are you asking for my email address?
The only reason I'm asking for your email address, which isn't required to submit a comment, is to provide a gravatar if you've created an account for yourself and associated your email address with a small image. If you have a gravatar created for the email address you submit, it will appear next to your comment. Otherwise nothing will appear.

What is a gravatar?
A gravatar is a "globally recognized avatar." You can get more information about gravatars, as well as create your own for free, at www.gravatar.com. You can also view my gravatar here.


Copyright © 2003 - 2009 Andrew Connell
Creative Commons License 
This work is licensed under a Creative Commons License
Site design by Heather Solomon.

 
 
MOSS WCM Training
Looking for MOSS 2007 WCM developer training? Look no further! I teach my 5-day hands-on and online WCM classes for developers I offer through my company: Critical Path Training.

Get more information on the WCM courses!


Upcoming Classes
 Hands-on WCM:
 Online WCM:
 » July 20-24, 2009


» Register today!