本文介绍了XSD:无法将名称'type'解析为(n)'类型定义'组件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的模式如下所示:

 <?xml version =1.0encoding =UTF-8?> 
< xsd:schema targetNamespace =http://www.mycompany.com/myproject/service/v1xmlns: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/v1elementFormDefault =qualified>

< xsd:import namespace =http://www.mycompany.com/otherproject/service/products/v1schemaLocation =products_v1.xsd/>
< xsd:import namespace =http://www.mycompany.com/myproject/service/common/v1schemaLocation =common_v1.xsd/>

< xsd:element name =GetProductRequesttype =tns:GetProductRequest>
< xsd:annotation>
< xsd:documentation>获取产品请求< / xsd:documentation>
< / xsd:annotation>
< / xsd:element>

< xsd:complexType name =GetProductRequest>
< xsd:annotation>
< xsd:documentation>获取产品请求< / xsd:documentation>
< / xsd:annotation>
< xsd:sequence>

< xsd:element name =IDtype =common:IDminOccurs =1maxOccurs =1>
< xsd:annotation>
< xsd:documentation> ID< / xsd:documentation>
< / xsd:annotation>
< / xsd:element>


< xsd:element name =Nametype =common:NameminOccurs =1maxOccurs =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/v1xmlns :xsd =http://www.w3.org/2001/XMLSchema
xmlns:tns =http://www.mycompany.com/myproject/service/common/v1
elementFormDefault = 合格 >


< xsd:complexType name =ID>
< xsd:annotation>
< xsd:documentation> ID< / xsd:documentation>
< / xsd:annotation>
< xsd:sequence>
< xsd:element name =Xtype =xsd:stringminOccurs =1maxOccurs =1>
< xsd:annotation>
< xsd:documentation> X< / xsd:documentation>
< / xsd:annotation>
< / xsd:element>
< xsd:element name =Ytype =xsd:stringminOccurs =1maxOccurs =1>
< xsd:annotation>
< xsd:documentation> Y< / xsd:documentation>
< / xsd:annotation>
< / xsd:element>
< / xsd:sequence>
< / xsd:complexType>

< xsd:element name =Nametype =xsd:string>
< xsd:annotation>
< xsd:documentation> Name< / xsd:documentation>
< / xsd:annotation>
< / xsd:element>
...

问题是我的模式能够解决一些来自common_v1.xsd的元素,有些不是。在上面的代码常见:ID不给出任何错误,但常见的:名称给出错误。



我无法理解为什么一些元素未解决。 p>

解决方案

从您显示的内容看起来,您有一个元素 Name common 命名空间,但不是类型,而您尝试在此使用类型:

 < xsd:element name =Nametype =common:NameminOccurs =1maxOccurs =1> 
< xsd:annotation>
< xsd:documentation> Name< / xsd:documentation>
< / xsd:annotation>
< / xsd:element>

所以创建一个类型 common:Name 或者使用< xsd:element ref =common:Name... />


I am defining the schema but on validating it in eclipse it gives following error.

My schema looks like following:

<?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 looks like following

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

Problem is my schema is able to resolve some of the elements from common_v1.xsd and some not. In above code common:ID does not give any error but common:Name gives error.

I am not able to understand why some of the elements are not resolved.

解决方案

From what you show it looks like you have an element Name in the common namespace, but not the type and you're trying to use the 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 either create a type common:Name or use <xsd:element ref="common:Name" .../> instead.

这篇关于XSD:无法将名称'type'解析为(n)'类型定义'组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-13 01:04