【问题标题】:Validation errors on xsd:keyrefxsd:keyref 上的验证错误
【发布时间】:2013-02-13 23:41:42
【问题描述】:

我对以下架构有疑问 我想将 job 元素的 jobGroup 属性与 jobGroup 元素的 name 属性“匹配”,但我无法通过验证来验证此成本约束

这是我的架构和应该失败的示例

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

【问题讨论】:

    标签: xml xsd-validation keyref


    【解决方案1】:

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

    试试这个:

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

    【讨论】:

      猜你喜欢
      • 2014-05-18
      • 2015-02-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-22
      • 2021-06-16
      • 2015-06-04
      • 2015-07-30
      相关资源
      最近更新 更多