How to use xsd file to check XML file in visual studio 2010

I just started learning xml, so I'm new to this domain. I want to check the xml file with the xsd file (just to find out how xsd works).

In VS 2010, I created an XML file "XSD file" and copied and pasted some code into it.

But when I make changes to the XML file, no warnings are expected. I think the reason is that I need to link the XSD file to my XML file.

I'm right? and if so, how can I bind XSD with XML?

+4
source share
2 answers

You must put the schema definition in your XML file as follows:

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

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

Make sure your schema file (xsd) is listed. If not, add it (add button). Also make sure that there are no more links to the same schema.

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

+2
source

In the xml file properties window in visual studio, you can select xsd for verification. Click the "..." button for the "Schemes" property and delete your scheme from the list (if it is not in the list, click the "Add" button and select a file). You will then receive warnings when your xml is invalid, and you will also get intellisense when editing xml. schema

Additionally (but it is not only required for verification in Visual Studio) you can also specify the namespace of your xml, it must correspond to the namespace that you defined in your XSD, and it can be an arbial string (usually a kind of URL) .

 <?xml version="1.0" encoding="utf-8" ?> <myrootelelemt xmlns="http://somearbitarystring.com/somemorestring.xsd"> ... </myrootelement> 
+3
source

Source: https://habr.com/ru/post/1445021/


All Articles