I am trying to design a schema for validating an xml format that is already used in an application (not much room for redesigning the xml).
我正在尝试设计一个模式来验证已经在应用程序中使用的xml格式(重新设计xml的空间不大)。
I am trying to utilize the key and keyref elements of the xml schema dictionary to validate identity constraints.
我正在尝试使用xml模式字典的key和keyref元素来验证身份约束。
One particular problem is with the way the xml models one to many relationship
一个特别的问题是xml对许多关系建模的方式
<spaceships>
<spaceship guns="gun1 gun2 gun3"/>
</spaceships>
<guns>
<gun id="gun1"/>
<gun id="gun2"/>
<gun id="gun3"/>
</guns>
I came up with this pair of key/keyref in my schema
我在我的模式中找到了一对key/keyref
<xs:key name="gunKey">
<xs:selector xpath="guns/gun" />
<xs:field xpath="@id" />
</xs:key>
<xs:keyref name="gunRef" refer="gunKey">
<xs:selector xpath="spaceships/spaceship" />
<xs:field xpath="@guns" />
</xs:keyref>
This doesn't validate with xerces protesting:
薛西斯*道:
Key 'gunRef' with value 'gun1 gun2 gun3' not found for identity constraint of element.
键'gunRef',值为'gun1 gun2 gun3',没有找到元素的标识约束。
Is there anyway of expressing in schema that the value of the list is comma separated list of references to another entity and still get the benefit of identity constraint validation?
在模式中是否有表示列表的值是逗号分隔的引用列表,并且仍然得到身份约束验证的好处?
1 个解决方案
#1
1
I'm afraid, that you can not create such reference for attribute like guns="gun1 gun2 gun3"
because gun1 gun2 gun3
is the simple string which is not automatically divided into 3 separate parts.
恐怕您不能为“gun1 gun2 gun3”之类的属性创建这样的引用,因为gun1 gun2 gun3是一个简单的字符串,不会自动划分为3个独立的部分。
EDIT 1: If want to match such attributes, look at this QA: XML schema; multiple from a list of valid attribute values
编辑1:如果想匹配这些属性,请查看这个QA: XML模式;有效属性值列表中的倍数
#1
1
I'm afraid, that you can not create such reference for attribute like guns="gun1 gun2 gun3"
because gun1 gun2 gun3
is the simple string which is not automatically divided into 3 separate parts.
恐怕您不能为“gun1 gun2 gun3”之类的属性创建这样的引用,因为gun1 gun2 gun3是一个简单的字符串,不会自动划分为3个独立的部分。
EDIT 1: If want to match such attributes, look at this QA: XML schema; multiple from a list of valid attribute values
编辑1:如果想匹配这些属性,请查看这个QA: XML模式;有效属性值列表中的倍数