1
我有兩個xml架構文件schema1.xsd schema2.xsd。 schema2.xsd是schema1.xsd 煥內進口我嘗試在JAXB解析schema1.xsd如下所示:無法解析名稱'common:DateRange'到(n)'類型定義'組件
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>