无法将名称'common:DateRange'解析为(n)'类型定义'组件

时间:2016-09-25 10:12:00

标签: 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: 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>

1 个答案:

答案 0 :(得分:0)

当我定义schema2.xsd路径的完整路径

时问题解决了