Xml xsd:keyref上的验证错误

Xml xsd:keyref上的验证错误,xml,xsd-validation,keyref,Xml,Xsd Validation,Keyref,我对以下模式有问题 我想将job元素的jobGroup属性与jobGroup元素的name属性“匹配”,但无法通过验证验证此costraints 这是我的模式,也是应该失败的例子 <?xml version="1.0" encoding="utf-8"?> <xs:schema targetNamespace="http://www.example.org/example" xmlns:xs="http://www.w3.org/2001/XML

我对以下模式有问题 我想将job元素的jobGroup属性与jobGroup元素的name属性“匹配”,但无法通过验证验证此costraints

这是我的模式,也是应该失败的例子

    <?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>

您忘记在选择器中使用完全限定名。您缺少名称空间

试试这个:

<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>

您忘记在选择器中使用完全限定名。您缺少名称空间

试试这个:

<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>