2014-12-30 52 views
6

我正在定義模式,但在eclipse中驗證它時會給出以下錯誤。XSD:無法將名稱'類型'解析爲(n)'類型定義'組件

src-resolve:無法將名稱'common:Name'解析爲(n)'類型定義'組件。

我的架構看起來像以下:

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

..... 

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

問題是我的架構能夠解決一些從common_v1.xsd元素和有些不是。在上面的代碼中常見:ID不會給出任何錯誤,但通用:名稱給出錯誤。

我無法理解爲什麼某些元素沒有解決。

回答

4

從你的表現是什麼樣子,你必須在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" .../>

1
<?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> 
相關問題