Introduction
This tip will show you how you can add an XSD to Visual Studio in order to enable Intellisense for that particular XSD when creating an XML file.
Background
For many integration solutions, we still rely heavily on parsing XML from some source. Often a SFTP location or file share or even a direct download link.
The issue with XML is that it is often quite prone to user errors. The XML needs to be formed just for the XML Parser to be able to process it. To make this easier, we came up with the XSD. Basically, it's a file with a definition containing the set of rules on which the XML should comply to.
Creating an XSD using Visual Studio is actually quite easy as well and it is useful if for example you have already defined a set of classes/entities and want just an XML file that follows your entity hierarchy and do a simple serialize/deserialize of the XML. (see: https://msdn.microsoft.com/en-us/library/x6c1kb0s%28v=vs.110%29.aspx)
But what if you want to write an XML in Visual Studio and ensure you are complying to the XSD and perhaps even get some intellisense?
Add XSD to Schema Validation
This is where this tip comes in. I decided to add this as I have stumbled at it when I had to write an example XML after I found that the third party I had send an XSD to implement had made lots of errors.
Checking to see if an XML matches validation can easily be done by validating it online. I've searched on Google and found http://www.freeformatter.com/xml-validator-xsd.html, but there were a whole bunch of validators. There's no need to write some C# code yourself to validate an XSD for these kinds of tests.
To add your XSD to the Schema Validation, you merely have to open the XML editor. For example, open the XML file in Visual Studio. Then once inside, go to properties and click on the Schemas Button.
Or in Visual Studio 2013, you can go to Schemas directly from the XML Menu. I've not noticed this in Visual Studio 2010 for example.
One you open the XML Schema, you will see a large list of XSD Schemas. The one which has a tick box in the "Use" column will be actually used in the XML that you are working on. So make sure that when you've added the XSD that you also set the tick on "Use".
Once you are working on the XML file than at least Visual Studio 2013, you can also just click F12 and you will be navigated directly to the XSD part that is relevant for that XML node you came from.
Also, there is no need for running some separate XML validator like the link I showed in the beginning as we now have IntelliSense and so also get warnings if the XML is not compliant to the used XSD Schemas.
All in all, I found this a very useful way to ensure that the XML samples I sent to the third parties that need to implement my XSD are valid.
Hopefully, you will find this tip useful.