如何将XSD类型导入根模式?

yeg*_*256 8 java xml xsd sax

这是我现有的XSD架构foo.xsd,它只声明了类型:

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" version="1.0"
  targetNamespace="foo">
  <xs:complexType name="alpha">
    <!-- skipped -->
  </xs:complexType>
</xs:schema>
Run Code Online (Sandbox Code Playgroud)

这是另一个声明元素的模式:

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" version="1.0"
  targetNamespace="foo">
  <xs:import schemaLocation="foo.xsd" namespace="foo" />
  <xs:element name="RootElement" type="alpha"/>
</xs:schema>
Run Code Online (Sandbox Code Playgroud)

这是我从Java中的SAX解析器得到的:

"The namespace attribute 'foo' of an <import> element information 
item must not be the same as the targetNamespace of the schema it exists in."
Run Code Online (Sandbox Code Playgroud)

我究竟做错了什么?

Pet*_*dea 15

当指定所涉及的XSD的targetNamespace(tns)属性并且相同时,仅允许xsd:include(targetNamespace属性不能将空字符串作为其值).

但是,可以包括没有来自具有tns的模式(s2)的tns的模式(s1); 净效果是s1组件假定s2模式的名称空间.这种用法通常被称为变色龙组合物.

这里描述了描述两者之间差异的SO的参考.