Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/392.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 从xsd架构生成源时出现问题_Java_Xml_Xsd_Jaxb_Schema - Fatal编程技术网

Java 从xsd架构生成源时出现问题

Java 从xsd架构生成源时出现问题,java,xml,xsd,jaxb,schema,Java,Xml,Xsd,Jaxb,Schema,在为我的项目生成源代码时,我遇到以下错误。我已将一些常见类型提取到名为CommonTypes.xsd的模式中,出现以下错误: org.xml.sax.SAXParseException: src-resolve.4.1: Error resolving component 'nonEmptyString'. It was detected that 'nonEmptyString' has no namespace, but components with no target namesp ac

在为我的项目生成源代码时,我遇到以下错误。我已将一些常见类型提取到名为CommonTypes.xsd的模式中,出现以下错误:

org.xml.sax.SAXParseException: src-resolve.4.1: Error resolving component 'nonEmptyString'. It was detected that 'nonEmptyString' has no namespace, but components with no target namesp
ace are not referenceable from schema document 'file:/C:/Workspace/CommonTypes.xsd'. If 'nonEmptyString' is
 intended to have a namespace, perhaps a prefix needs to be provided. If it is intended that 'nonEmptyString' has no namespace, then an 'import' without a "namespace" attribute should
be added to 'file:/C:/Workspace/lps-performance-calculation-service/pcs-data/src/main/resources/xsd/calc/lps/CommonTypes.xsd'.
以下简单类型在我的CommonTypes.xsd架构中定义如下:

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
            xmlns:unit="http://www.mywebsite.com/unit"
            xmlns:types="http://www.mywebsite.com/types"
            elementFormDefault="qualified" attributeFormDefault="unqualified"
            targetNamespace="http://www.mywebsite.com//types">
    <!-- import types -->
    <xsd:import namespace="http://www.mywebsite.com/unit"/>
    <!-- other common types -->
    <xsd:simpleType name="nonEmptyString">
        <xsd:restriction base="xsd:string">
            <xsd:minLength value="1"/>
            <xsd:pattern value=".*[^\s].*"/>
        </xsd:restriction>
    </xsd:simpleType>

导致错误的第241行如下:

<xsd:complexType name="Message">
        <xsd:simpleContent>
            <xsd:extension base="nonEmptyString">
                <xsd:attribute type="xsd:string" name="code" use="required"/>
                <xsd:attribute name="category" use="required">
                    <xsd:simpleType>
                        <xsd:restriction base="xsd:token">
                            <xsd:enumeration value="Error"/>
                            <xsd:enumeration value="Info"/>
                        </xsd:restriction>
                    </xsd:simpleType>
                </xsd:attribute>
                <xsd:attribute type="xsd:string" name="component" use="required"/>
            </xsd:extension>
        </xsd:simpleContent>
    </xsd:complexType>


你知道是什么导致了这个错误吗?我尝试搜索StackOverflow并尝试使用targetNamespace和xmlns,但没有成功。

您试图引用一个简单的

  • 名称“非空字符串”
  • 命名空间“”
但是这个XSD中定义了简单类型“nonEmptyString”,它具有
targetNamespace=”http://www.mywebsite.com//types“
。所以你应该指的是一个简单的类型

  • 名称“非空字符串”
  • 名称空间“http://www.mywebsite.com//types"
您只需更改以下内容:

为此:


您试图引用的是一个具有

  • 名称“非空字符串”
  • 命名空间“”
但是这个XSD中定义了简单类型“nonEmptyString”,它具有
targetNamespace=”http://www.mywebsite.com//types“
。所以你应该指的是一个简单的类型

  • 名称“非空字符串”
  • 名称空间“http://www.mywebsite.com//types"
您只需更改以下内容:

为此:


您需要在相应的命名空间中导入
非空字符串
,并通过前缀使此命名空间可引用

为此,请添加
xmlns:types=”http://www.mywebsite.com/types“
到导入架构的
xsd:schema

还可以在导入架构的
xsd:import
中提供
名称空间
。应该是这样的:

<xsd:import
    namespace="http://www.mywebsite.com/types"
    schemaLocation="calc/lps/CommonTypes.xsd"/>


然后,您应该能够将
非空字符串
类型引用为
类型:非空字符串

您需要在相应的命名空间中导入
非空字符串
,并通过前缀使此命名空间可引用

为此,请添加
xmlns:types=”http://www.mywebsite.com/types“
到导入架构的
xsd:schema

还可以在导入架构的
xsd:import
中提供
名称空间
。应该是这样的:

<xsd:import
    namespace="http://www.mywebsite.com/types"
    schemaLocation="calc/lps/CommonTypes.xsd"/>

然后您应该能够将
非空字符串
类型引用为
类型:非空字符串