我正在定义模式,但是在eclipse中验证它会产生以下错误。
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中的一些元素而某些元素不能解析。在上面的代码common:ID不会给出任何错误但是常见:Name给出了错误。
我无法理解为什么有些元素没有得到解决。
答案 0 :(得分:6)
根据您显示的内容,您似乎在Name
命名空间中有一个元素common
,但不是类型,并且您尝试在此处使用该类型:
<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 :(得分: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>