4

I've just started to learn xml, so i'm a beginner in this domain. I want to validate xml file against xsd file (just to figure out how xsd works).

In VS 2010 i created XML file an' XSD file and copied and pasted some code into it.

But when i make changes in the XML file there is no warnings as expected. I think the reason is that i need to bind XSD file to my XML file.

Am i right? and if so, how can i bind XSD to XML?

Aleksei Chepovoi
  • 3,915
  • 8
  • 39
  • 77
  • Does this answer your question? [XML Validation with XSD in Visual Studio IDE](https://stackoverflow.com/questions/3161224/xml-validation-with-xsd-in-visual-studio-ide) – GSerg May 24 '23 at 11:35

2 Answers2

3

In the properties window of the xml file in visual studio you can chose the xsd to validate against. Click the "..." button in for the "Schemas" property and sleect your schema from the list (if it is not listed, click the add button and select your file). Then you will get warnings when your xml is invalid and you will also get intellisense when you edit your xml. schema

Additionally (but it is not required just for validation in Visual Studio) you can also speciy the namespace of your xml, it should match the namespace you defined in your XSD and it can be an arbitary string (usually some sort of url).

<?xml version="1.0" encoding="utf-8" ?>
<myrootelelemt xmlns="http://somearbitarystring.com/somemorestring.xsd">
...
</myrootelement>
bitbonk
  • 48,890
  • 37
  • 186
  • 278
2

You have to put the schema definition in your xml file like this:

<?xml version="1.0" encoding="utf-8" ?>
<project xmlns="http://ProjectBase/Config.xsd" >
...

When the xml file is opened, VS 2010 displays new Menu Item XML. Open it and select the last MenuItem Schemas....

Assure that your schema file (xsd) is in the list. If not, add it (add button). Also be sure that there are not more references to the same schema.

Finally, use the first column to check which schema should be used for validation/intellisense

Radim Köhler
  • 122,561
  • 47
  • 239
  • 335