考虑这个XSD架构,得到以下图表
<?xml version="1.0" encoding="UTF-8"?>
<s:schema xmlns:s="http://www.w3.org/2001/XMLSchema"
xmlns:target="http://www.url.com/validation"
xmlns:vc="http://www.w3.org/2007/XMLSchema-versioning"
elementFormDefault="qualified" attributeFormDefault="unqualified">
<s:element name="myObjects" type="typeObjects">
<s:unique name="uniqueObjectId">
<s:selector xpath="myObject"/>
<s:field xpath="id"/>
</s:unique>
</s:element>
<s:complexType name="typeObjects">
<s:sequence maxOccurs="unbounded">
<s:element name="myObject">
<s:complexType>
<s:complexContent>
<s:extension base="typeObject"/>
</s:complexContent>
</s:complexType>
</s:element>
</s:sequence>
</s:complexType>
<s:complexType name="typeObject">
<s:sequence>
<s:element name="id" type="s:int"/>
</s:sequence>
</s:complexType>
</s:schema>
请注意在&#34; id&#34;上设置的唯一约束。元素,输入为s:int。
以下实例XML仍然可以验证,即使具有相同的<id>1</id>
两次!
<?xml version="1.0" encoding="utf-8"?>
<myObjects
xmlns:target="http://www.url.ch/validation"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="unique.xsd">
<myObject>
<id>1</id>
</myObject>
<myObject>
<id>1</id>
</myObject>
</myObjects>
如果我将元素类型更改为 s:string
,我可以强制执行失败条件我在oXygen XML和ALtova XML Spy中分别尝试了相同的结果验证。
问题显然是否是XSD的唯一约束实现中的错误或已知限制?
答案 0 :(得分:0)
你的xsd看起来很好,我用氧气证实了它。我收到了预期的错误:
SELECT l.lead_id, a.code as attributeCode, ln.content as noteContent, ln.task_type_id, tt.type_name
FROM leads l JOIN
leads_notes ln
ON ln.lead_id = l.lead_id JOIN
task_types tt
ON tt.task_type_id = ln.task_type_id JOIN
leads_attributes la
ON la.lead_id = l.lead_id JOIN
attributes a
ON a.attribute_id = la.attribute_id
WHERE (l.ambassador=1 OR l.rents_bike=1) AND
(l.city <> '') AND
(l.address <>'' OR l.address2 <>'') AND
(l.country_id <> '') AND
(la.attribute_id IN ($attributes_id)) AND
(l.lead_id = $lead_id);
我看到验证适用于SAXON-EE 9.6.0.7
cvc-identity-constraint.4.1: Duplicate unique value [1] declared for identity
constraint "uniqueObjectId" of element "myObjects".
和其他引擎。
尝试检查您的验证方案,缓存和文件名。
答案 1 :(得分:0)