XSD: Unable to resolve name "type" for component (n) "type definition"

I am defining a schema, but when checking it in eclipse it gives the following error.

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

My diagram is as follows:

<?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 is as follows

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

The problem is that my schema may allow some elements from common_v1.xsd and some not. In the above code, generic: ID does not give any error, but is generic: Name gives an error.

I cannot understand why some of the elements are not allowed.

+6
source share
2 answers

From what you are showing, it looks like you have a Name element in the common namespace, but not a type, and you are trying to use this type here:

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

So, create a common:Name type or use <xsd:element ref="common:Name" .../> .

+4
source
 <?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> 
+1
source

Source: https://habr.com/ru/post/980309/


All Articles