5

How do I validate an xml document against an xsd in Visual Studio 2010?

Thanks.

2 Answers 2

8

Open you XML file in VS2010; in the Properties tool window (F4) there is a Schemas property. List the XSD you want in there. Once done, the errors/warnings will show up in the Error List tool window.

0
0

There are a few things you need. First the XML Document must be associated with the Schema:

<XmlDocument xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xsi:noNamespaceSchemaLocation="C:\Code\Schema.xsd">
</XmlDocument>

Now you need to have that Schema XSD Added into your Project. Now when you open the XML Document you should get intellisence and errors / warnings shown as you would errors in your normal C#/VB/etc/ code.

2
  • Hi Dave, you don't need to modify the XML to get what you described (see my answer, I get I beat you by seconds ;)... in fact, VS2010 is "smart" enough that even if you close and reopen the file, it'll remember the values you've set in the Properties window. You also get Intellisense.... Jan 24, 2012 at 14:49
  • Never knew that, all ours had the path set :)
    – DaveShaw
    Jan 24, 2012 at 14:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.