我已经搜索了一段时间,得出的结论是可能无法更改每个属性值的验证.
I have been searching for a while now, and came to the conclusion it may not be possible to change the validation per value of an attribute.
例如我有两个action"节点,都有一个type"属性和两个元素(name"和description")
For example I have two "action" nodes, both with a "type" attribute and two elements ("name" and "description")
仅当type"属性的值为1"时,它有一个带有abc"子元素的a"元素,当type"属性为2"时,它有一个带有的"元素bla"然而"子元素.
Only when the value of the "type" attribute is "1" it has an "a" element with "abc" child elements and when the "type" attibute is "2" it has a "bla" element with "yet" child elements.
类型 1 的示例
<action type="1">
<name>yup</name>
<description>yyy</description>
<a>
<abc>false</abc>
</a>
</action>
类型 2 的示例
<action type="2">
<name>yup2</name>
<description>RRR</description>
<bla>
<yet />
</bla>
</action>
我想创建一个 XSD* 来检查这两种类型,这可能吗?如果是这样,如何?
I want to create one XSD* who whould check both types, is this possible? And if so, how?
您说得对,XSD 1.0 是不可能的,它是 MSSQL 支持的唯一 XSD 版本.你能得到的最好的方法是在 a 和 bla 之间创建一个选择,也许对属性 type 值等进行一些限制.下面是一个插图.
You are right, it is not possible with XSD 1.0 which is the only XSD version supported by MSSQL. The best you can get is to create a choice between a and bla, maybe place some constraints on attribute type values, etc. Below is an illustration.
<?xml version="1.0" encoding="utf-8"?>
<!--XML Schema generated by QTAssistant/XML Schema Refactoring (XSR) Module (http://www.paschidev.com)-->
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="action">
<xs:complexType>
<xs:sequence>
<xs:element name="name" type="xs:string" />
<xs:element name="description" type="xs:string" />
<xs:choice>
<xs:element name="a">
<xs:complexType>
<xs:sequence>
<xs:element name="abc" type="xs:boolean" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="bla">
<xs:complexType>
<xs:sequence>
<xs:element name="yet" type="xs:anyType" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:sequence>
<xs:attribute name="type" type="xs:unsignedByte" use="required" />
</xs:complexType>
</xs:element>
</xs:schema>
如果您控制 XML 结构,并且仍然想使用某些属性来控制内容模型,那么 xsi:type 是 XSD 1.0 中唯一的方法.
If you control the XML structure, and still want to use some attribute to control the content model, then xsi:type is the only way to do it in XSD 1.0.
这篇关于如何创建在属性值验证方面不同的 XSD?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
我可以在不编写 SQL 查询的情况下找出数据库列表Can I figure out a list of databases and the space used by SQL Server instances without writing SQL queries?(我可以在不编写 SQL 查询的情况下
如何创建对 SQL Server 实例的登录?How to create a login to a SQL Server instance?(如何创建对 SQL Server 实例的登录?)
如何通过注册表搜索知道SQL Server的版本和版本How to know the version and edition of SQL Server through registry search(如何通过注册表搜索知道SQL Server的版本和版本)
为什么会出现“数据类型转换错误"?使用 ExWhy do I get a quot;data type conversion errorquot; with ExecuteNonQuery()?(为什么会出现“数据类型转换错误?使用 ExecuteNonQuery()?)
如何将 DataGridView 中的图像显示到 PictureBox?How to show an image from a DataGridView to a PictureBox?(如何将 DataGridView 中的图像显示到 PictureBox?)
WinForms 应用程序设计——将文档从 SQL Server 移动WinForms application design - moving documents from SQL Server to file storage(WinForms 应用程序设计——将文档从 SQL Server 移动到文件存