XSD:无法将名称"type"解析为"type definition"组件

15

我正在定义架构,但在使用eclipse验证时,出现以下错误:

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

我的架构看起来像这样:

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

.....

常用版本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>
......

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

我不明白为什么有些元素无法解析。

2个回答

10

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

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

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

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

您需要为此tns编写复杂类型,否则会导致无法解析类型(n)错误,例如:

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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接