Java 从xsd架构生成源时出现问题
在为我的项目生成源代码时,我遇到以下错误。我已将一些常见类型提取到名为CommonTypes.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
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,但没有成功。您试图引用一个简单的
- 名称“非空字符串”
- 命名空间“”
targetNamespace=”http://www.mywebsite.com//types“
。所以你应该指的是一个简单的类型
- 名称“非空字符串”
- 名称空间“http://www.mywebsite.com//types"
为此:
您试图引用的是一个具有
- 名称“非空字符串”
- 命名空间“”
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"/>
然后您应该能够将非空字符串
类型引用为类型:非空字符串