eclipse XSD:无法将名称“类型”解析为 (n)“类型定义”组件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/27706704/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 05:28:55  来源:igfitidea点击:

XSD: Cannot resolve the name 'type' to a(n) 'type definition' component

eclipsexsdxsd-validation

提问by Balkrishan Nagpal

I am defining the schema but on validating it in eclipse it gives following error.

我正在定义模式,但在 eclipse 中验证它时会出现以下错误。

src-resolve: Cannot resolve the name 'common:Name' to a(n) 'type definition' component.

src-resolve:无法将名称“common:Name”解析为 (n)“类型定义”组件。

My schema looks like following:

我的架构如下所示:

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema targetNamespace="http://www.mycompany.com/myproject/service/v1"              xmlns:xsd="http://www.w3.org/2001/XMLSchema"
        xmlns:tns="http://www.mycompany.com/myproject/service/v1"            
        xmlns:product="http://www.mycompany.com/otherproject/service/products/v1"
        xmlns:common="http://www.mycompany.com/myproject/service/common/v1" elementFormDefault="qualified">

<xsd:import namespace="http://www.mycompany.com/otherproject/service/products/v1" schemaLocation="products_v1.xsd" />
<xsd:import namespace="http://www.mycompany.com/myproject/service/common/v1" schemaLocation="common_v1.xsd" />          

<xsd:element name="GetProductRequest" type="tns:GetProductRequest">
    <xsd:annotation>
        <xsd:documentation>Get Product Request</xsd:documentation>
    </xsd:annotation>
</xsd:element>  

<xsd:complexType name="GetProuctRequest">
    <xsd:annotation>
        <xsd:documentation>Get Product Request</xsd:documentation>
    </xsd:annotation>
    <xsd:sequence>

        <xsd:element name="ID" type="common:ID" minOccurs="1" maxOccurs="1">
            <xsd:annotation>
                <xsd:documentation>ID</xsd:documentation>
            </xsd:annotation>
        </xsd:element>


        <xsd:element name="Name" type="common:Name" minOccurs="1" maxOccurs="1">
            <xsd:annotation>
                <xsd:documentation>Name</xsd:documentation>
            </xsd:annotation>
        </xsd:element>  

    </xsd:sequence>
</xsd:complexType>

.....

and common_v1.xsd looks like following

和 common_v1.xsd 如下所示

<xsd:schema targetNamespace="http://www.mycompany.com/myproject/service/common/v1" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
        xmlns:tns="http://www.mycompany.com/myproject/service/common/v1" 
        elementFormDefault="qualified">


<xsd:complexType name="ID">
    <xsd:annotation>
        <xsd:documentation>ID</xsd:documentation>
    </xsd:annotation>
    <xsd:sequence>
        <xsd:element name="X" type="xsd:string" minOccurs="1" maxOccurs="1">
            <xsd:annotation>
                <xsd:documentation>X</xsd:documentation>
            </xsd:annotation>
        </xsd:element>
        <xsd:element name="Y" type="xsd:string" minOccurs="1" maxOccurs="1">
            <xsd:annotation>
                <xsd:documentation>Y</xsd:documentation>
            </xsd:annotation>
        </xsd:element>
    </xsd:sequence>
</xsd:complexType>  

<xsd:element name="Name" type="xsd:string">
    <xsd:annotation>
        <xsd:documentation>Name</xsd:documentation>
    </xsd:annotation>
</xsd:element>
......

Problem is my schema is able to resolve some of the elements from common_v1.xsd and some not. In above code common:ID does not give any error but common:Name gives error.

问题是我的架构能够解析 common_v1.xsd 中的一些元素,而有些则不能。在上面的代码中 common:ID 没有给出任何错误,但是 common:Name 给出了错误。

I am not able to understand why some of the elements are not resolved.

我不明白为什么有些元素没有得到解决。

采纳答案by lexicore

From what you show it looks like you have an element Namein the commonnamespace, but not the type and you're trying to use the type here:

从您显示的内容来看,您似乎Namecommon命名空间中有一个元素,但没有类型,并且您正在尝试在此处使用该类型:

    <xsd:element name="Name" type="common:Name" minOccurs="1" maxOccurs="1">
        <xsd:annotation>
            <xsd:documentation>Name</xsd:documentation>
        </xsd:annotation>
    </xsd:element>

So either create a type common:Nameor use <xsd:element ref="common:Name" .../>instead.

所以要么创建一个类型,common:Name要么<xsd:element ref="common:Name" .../>改用。

回答by anil

<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema" 
targetNamespace="http://www.bharatsecurity.com/Patients"
 xmlns:tns="http://www.bharatsecurity.com/Patients" 
 elementFormDefault="qualified">
<element name="patient" type="tns:Patients"></element>

you need to write complex type for this tns otherwise it will result in cannot resolve type (n) error  like :- 


<complexType name="Patients">
<sequence>
<element name="id" type="int" />
<element name="name" type="string"></element>
<element name="gender" type="string"></element>
<element name="age" type="int"></element>
</sequence>
</complexType>
</schema>