2014-12-30 13 views
6

Tôi định nghĩa lược đồ nhưng trên xác thực nó trong nhật thực nó cho lỗi sau.XSD: Không thể giải quyết tên 'loại' thành thành phần (n) 'định nghĩa kiểu'

src-resolve: Không thể giải quyết tên 'common: Name' thành thành phần định nghĩa loại (n) '.

schema của tôi trông giống như sau:

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

..... 

và common_v1.xsd trông giống như sau

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

Vấn đề là schema của tôi là có thể giải quyết một số các yếu tố từ common_v1.xsd và một số thì không. Trong mã trên phổ biến: ID không đưa ra bất kỳ lỗi nào nhưng thông thường: Tên đưa ra lỗi.

Tôi không thể hiểu tại sao một số yếu tố không được giải quyết.

Trả lời

4

Từ những gì bạn thấy có vẻ như bạn có một yếu tố Name trong không gian tên common, nhưng không phải là loại hình và bạn đang cố gắng sử dụng các loại ở đây:

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

Vì vậy, hoặc tạo ra một loại common:Name hay sử dụng <xsd:element ref="common:Name" .../> để thay thế.

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> 
Các vấn đề liên quan