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).
我刚开始学习xml,所以我是这个领域的初学者。我想针对xsd文件验证xml文件(只是想弄清楚xsd是如何工作的)。
In VS 2010 i created XML file an' XSD file and copied and pasted some code into it.
在VS 2010中,我创建了一个'XSD文件的XML文件,并将一些代码复制并粘贴到其中。
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.
但是当我在XML文件中进行更改时,没有预期的警告。我认为原因是我需要将XSD文件绑定到我的XML文件。
Am i right? and if so, how can i bind XSD to XML?
我对吗?如果是这样,我如何将XSD绑定到XML?
2 个解决方案
#1
2
You have to put the schema definition in your xml file like this:
您必须将模式定义放在xml文件中,如下所示:
<?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...
.
打开xml文件时,VS 2010将显示新的菜单项XML。打开它并选择最后一个MenuItem模式....
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.
确保您的模式文件(xsd)在列表中。如果没有,请添加(添加按钮)。还要确保没有更多对同一模式的引用。
Finally, use the first column to check which schema should be used for validation/intellisense
最后,使用第一列检查哪个模式应该用于验证/智能感知
#2
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.
在visual studio中的xml文件的属性窗口中,您可以选择要对其进行验证的xsd。单击“Schemas”属性中的“...”按钮,并从列表中清除架构(如果未列出,请单击“添加”按钮并选择文件)。然后,当xml无效时,您将收到警告,并且在编辑xml时也会获得智能感知。
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).
另外(但不仅仅是在Visual Studio中进行验证)您还可以指定xml的命名空间,它应该与您在XSD中定义的命名空间匹配,它可以是一个任意字符串(通常是某种类型的URL)。
<?xml version="1.0" encoding="utf-8" ?>
<myrootelelemt xmlns="http://somearbitarystring.com/somemorestring.xsd">
...
</myrootelement>
#1
2
You have to put the schema definition in your xml file like this:
您必须将模式定义放在xml文件中,如下所示:
<?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...
.
打开xml文件时,VS 2010将显示新的菜单项XML。打开它并选择最后一个MenuItem模式....
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.
确保您的模式文件(xsd)在列表中。如果没有,请添加(添加按钮)。还要确保没有更多对同一模式的引用。
Finally, use the first column to check which schema should be used for validation/intellisense
最后,使用第一列检查哪个模式应该用于验证/智能感知
#2
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.
在visual studio中的xml文件的属性窗口中,您可以选择要对其进行验证的xsd。单击“Schemas”属性中的“...”按钮,并从列表中清除架构(如果未列出,请单击“添加”按钮并选择文件)。然后,当xml无效时,您将收到警告,并且在编辑xml时也会获得智能感知。
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).
另外(但不仅仅是在Visual Studio中进行验证)您还可以指定xml的命名空间,它应该与您在XSD中定义的命名空间匹配,它可以是一个任意字符串(通常是某种类型的URL)。
<?xml version="1.0" encoding="utf-8" ?>
<myrootelelemt xmlns="http://somearbitarystring.com/somemorestring.xsd">
...
</myrootelement>