通过 xsd:include 组合 XSD 时名称冲突?

Name clashes when combining XSD via xsd:include?

我目前正在阅读 Bill Evjen、Kent Sharkey、Thiru Thangarathinam、Michael Kay、Alessandro Vernet 的 Professional XML , 山姆弗格森。

我是初学者,正在尝试了解 XML 模式文档的基本结构。 作者提出了如何将 XML Schema Documents 放在一起的概念。

导入

Imports allow you to import another entire XML Schema document into the one that you are already working with. This is usually done if the two varying XML Schema documents utilize different namespaces. This import is done using the <import> element and two attributes—namespace and schemaLocation.

包括

The <include> element is used if the other schema has the same namespace or makes use of no namespace. It is quite similar to the <import> element and is a good way to combine two schemas with little work.

我发现自己对线条很困惑, 如果另一个模式具有 include 元素,则使用 相同的命名空间 或不使用命名空间。

如果他们有相同的命名空间,会不会导致冲突 在相同的 元素之间 定义在 两个模式 ?

如果您通过 xsd:include 合并来自同一命名空间或没有命名空间的 XSD,是的,可能会出现命名冲突,但是当您选择通常使用 xsd:include 时您可以控制两个 XSD 并且可以避免冲突。

当您从不同的来源组合 XSD 时,通常不受您的控制,更需要有单独的名称空间来避免组件名称冲突。

另见 What's the difference between xsd:include and xsd:import?