src-resolve:无法解析名称' at:AutomaticTask'到(n)'元素声明'零件

时间:2017-03-23 17:01:34

标签: xml xsd xsd-validation

我看了一些类似的问题,但仍然无法解决我的问题。

src-resolve: Cannot resolve the name 'at:AutomaticTask' to a(n) 'element declaration' component.

我有main.xsd导入task.xsd,如bellow。

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:at="http://my.sample.com/bpmn" targetNamespace="http://www.omg.org/spec/BPMN/20100524/MODEL" elementFormDefault="qualified">
   <xs:import namespace="http://my.sample.com/bpmn" schemaLocation="task.xsd" />
   <xs:element name="definitions">
      <xs:complexType>
         <xs:sequence>
            <xs:element name="userTask">
               <xs:complexType>
                  <xs:choice maxOccurs="unbounded">
                     <xs:element name="extensionElements">
                        <xs:complexType>
                           <xs:choice maxOccurs="unbounded">
                              <xs:element ref="at:AutomaticTask" />
                           </xs:choice>
                        </xs:complexType>
                     </xs:element>
                  </xs:choice>
                  <xs:attribute name="id" type="xs:string" use="required" />
                  <xs:attribute name="name" type="xs:string" use="required" />
               </xs:complexType>
            </xs:element>
         </xs:sequence>
      </xs:complexType>
   </xs:element>
</xs:schema>

我的task.xsd如下。两个xsd文件位于test / resoures下的同一个文件夹中,我正在编写单元测试。

<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
           targetNamespace="http://my.sample.com/bpmn"
           xmlns="http://my.sample.com/bpmn"
           elementFormDefault="qualified">
    <xs:element name="AutomaticTask">
        <xs:complexType>
            <xs:attribute name="name" type="xs:string" />
            <xs:attribute name="id" type="xs:string" use="required" />
        </xs:complexType>
    </xs:element>
</xs:schema>

这是要验证的xml。

<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:at="http://my.sample.com/bpmn">
    <userTask id="123xb" name="task1">
        <extensionElements>
            <at:automaticTask name="myTask" id="0318ba00" />
        </extensionElements>
        <incoming>SequenceFlow_1x3hpv4</incoming>
        <outgoing>SequenceFlow_02ko1r6</outgoing>
    </userTask>
</definitions>

1 个答案:

答案 0 :(得分:2)

将导入的XSD(xs:schema/@targetNamespace)中的task.xsdmy.sample.com/bpmn更改为http://my.sample.com/bpmn,以匹配xmlns:at命名空间前缀声明和{{ 1}}在导入XSD(xs:import/@namespace)。

以下是修复的XSD以消除错误:

main.xsd

main.xsd

task.xsd

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
           xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL"
           xmlns:at="http://my.sample.com/bpmn"
           targetNamespace="http://www.omg.org/spec/BPMN/20100524/MODEL"
           elementFormDefault="qualified">
  <xs:import namespace="http://my.sample.com/bpmn" schemaLocation="task.xsd" />
  <xs:element name="definitions">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="userTask">
          <xs:complexType>
            <xs:choice maxOccurs="unbounded">
              <xs:element name="extensionElements">
                <xs:complexType>
                  <xs:choice maxOccurs="unbounded">
                    <xs:element ref="at:AutomaticTask" />
                  </xs:choice>
                </xs:complexType>
              </xs:element>
            </xs:choice>
            <xs:attribute name="id" type="xs:string" use="required" />
            <xs:attribute name="name" type="xs:string" use="required" />
          </xs:complexType>
        </xs:element>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>

<强>更新

以下修复的XML文件现在对上述XSD有效:

main.xml中

<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
           targetNamespace="http://my.sample.com/bpmn"
           xmlns="http://my.sample.com.com/bpmn"
           elementFormDefault="qualified">
  <xs:element name="AutomaticTask">
    <xs:complexType>
      <xs:attribute name="name" type="xs:string" />
      <xs:attribute name="id" type="xs:string" use="required" />
    </xs:complexType>
  </xs:element>
</xs:schema>