Java 无法解析名称';通用:日期范围';到a(n)和"x27 ;;类型定义';成分
我有两个xml模式文件schema1.xsd schema2.xsd。 schema2.xsd在schema1.xsd中导入 我尝试在JAXB中解析schema1.xsd,如下所示:Java 无法解析名称';通用:日期范围';到a(n)和"x27 ;;类型定义';成分,java,xml,xsd,jaxb,schema,Java,Xml,Xsd,Jaxb,Schema,我有两个xml模式文件schema1.xsd schema2.xsd。 schema2.xsd在schema1.xsd中导入 我尝试在JAXB中解析schema1.xsd,如下所示: Schema schema = factory.newSchema(new StreamSource(schemaString)); 我得到了以下例外: org.xml.sax.SAXParseException; lineNumber: 12; columnNumber: 62; src-resolve: Ca
Schema schema = factory.newSchema(new StreamSource(schemaString));
我得到了以下例外:
org.xml.sax.SAXParseException; lineNumber: 12; columnNumber: 62; src-resolve: Cannot resolve the name 'common:DateRange' to a(n) 'type definition' component.
Schema1.xsd
<?xml version="1.0" encoding="UTF-8" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.example.com" xmlns="http://www.example.com"
xmlns:common="http://www.example.com/common">
<xs:import namespace="http://www.example.com/common" schemaLocation="schema2.xsd" />
<xs:element name="exType" type="ExampleType" />
<xs:complexType name="ExampleType">
<xs:sequence>
<xs:sequence minOccurs="0">
<xs:element name="activeDates" type="common:DateRange" />
</xs:sequence>
</xs:sequence>
</xs:complexType>
</xs:schema>
Schema2.xsd:
<?xml version="1.0" encoding="UTF-8" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns="http://www.example.com/common"
targetNamespace="http://www.example.com/common">
<xs:complexType name="DateRange">
<xs:sequence>
<xs:element name="startDate" type="xs:dateTime"/>
<xs:element name="endDate" type="xs:dateTime"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
我定义schema2.xsd路径的完整路径时解决的问题我定义schema2.xsd路径的完整路径时解决的问题您是否在调用xsd的schemaLocation下指定了相对路径?您是否在调用xsd的schemaLocation下指定了相对路径?