首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >xsd:keyref上的验证错误

xsd:keyref上的验证错误
EN

Stack Overflow用户
提问于 2013-02-13 11:52:15
回答 1查看 102关注 0票数 1

我想要将job元素的jobGroup属性与jobGroup元素的name属性“匹配”,但是我无法通过验证来验证这个约束

这是我的模式和应该失败的示例。

代码语言:javascript
复制
    <?xml version="1.0" encoding="utf-8"?>
<xs:schema targetNamespace="http://www.example.org/example" 
           xmlns:xs="http://www.w3.org/2001/XMLSchema" 
           xmlns:tns="http://www.example.org/example"   
           elementFormDefault="qualified" >

    <xs:element name="cluster" type="tns:clusterType">
        <xs:keyref name="jobGroupKeyRef" refer="tns:jobGroupKey">
            <xs:selector xpath=".//job"></xs:selector>
            <xs:field xpath="@jobGroup"></xs:field>
        </xs:keyref>
        <xs:key name="jobGroupKey">
            <xs:selector xpath=".//jobGroup"></xs:selector>
            <xs:field xpath="@name"></xs:field>
        </xs:key>
    </xs:element>

    <xs:complexType name="jobType">
      <xs:attribute name="id" 
                    type="xs:positiveInteger" 
                    use="required"/>
      <xs:attribute name="submissionTime" 
                    type="xs:dateTime" 
                    use="required"/>
      <xs:attribute name="jobGroup" 
                    type="xs:string" 
                    default="default"/>
    </xs:complexType>


    <xs:complexType name="jobGroupType">
      <xs:attribute name="name" 
                    type="xs:string" 
                    use="required"/>
      <xs:attribute name="description" 
                    type="xs:string" 
                    default=""/>
    </xs:complexType>


  <xs:complexType name="clusterType">
      <xs:choice minOccurs="1" maxOccurs="unbounded">
        <xs:element name="job" 
                    type="tns:jobType"  
                    minOccurs="0" 
                    maxOccurs="unbounded"/>         
        <xs:element name="jobGroup" 
                    type="tns:jobGroupType"  
                    minOccurs="0" 
                    maxOccurs="unbounded"/>
      </xs:choice>
      <xs:attribute name="name" 
                    type="xs:string" 
                    use="required"/>
    </xs:complexType>

</xs:schema>


<cluster xmlns="http://www.example.org/example" 
  xmlns:xs="http://www.w3.org/2001/XMLSchema-instance" 
  xs:schemaLocation="http://www.example.org/example XSDFile.xsd" 
  name="CLUSTER1" >
    <job submittedHost="HOST1" 
      id="1" 
      submissionTime="2009-03-31T17:40:35.000+02:00" 
      jobGroup="default"></job>
    <job submittedHost="HOST2" 
      id="2" 
      submissionTime="2009-03-31T17:40:35.000+02:00"  
      jobGroup="wrongName"></job>
    <jobGroup name="default" 
      description="Job Group number 1"></jobGroup>

</cluster>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-02-13 14:37:48

您忘记在选择器中使用完全限定的名称。您丢失了命名空间。

试试这个:

代码语言:javascript
复制
<xs:element name="cluster" type="tns:clusterType">
    <xs:keyref name="jobGroupKeyRef" refer="tns:jobGroupKey">
        <xs:selector xpath=".//tns:job"></xs:selector>
        <xs:field xpath="@jobGroup"></xs:field>
    </xs:keyref>
    <xs:key name="jobGroupKey">
        <xs:selector xpath=".//tns:jobGroup"></xs:selector>
        <xs:field xpath="@name"></xs:field>
    </xs:key>
</xs:element>
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14852941

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档