我可以让一个 XML 架构 (XSD) 包含另一个 XML 架构吗?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/332792/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-06 12:13:58  来源:igfitidea点击:

Can I have one XML Schema (XSD) include another XML-Schema?

xmlxsdinclude

提问by Robert Gould

I currently have two XSD schemes and one is a "light" version of the other. Right now I have everything in the "light" version repeated in the "complete" schema, but this becomes a pain when I need to make a change, and it goes against the DRY principle anyways, so I was wondering if there was an element that served to include another schema into a schema, so I can have my "complete" inherit from the "light" schema to reduce maintenance hurdles.

我目前有两个 XSD 方案,一个是另一个的“轻型”版本。现在我在“完整”模式中重复了“轻”版本中的所有内容,但是当我需要进行更改时这变得很痛苦,并且无论如何它都违反了 DRY 原则,所以我想知道是否有一个元素它用于将另一个模式包含到模式中,因此我可以从“轻量级”模式继承“完整”模式以减少维护障碍。

回答by jdmichal

There are two methods for this.

有两种方法可以做到这一点。

<xsd:include schemaLocation="pathToFile" />should be used for including files of the same namespace.

<xsd:include schemaLocation="pathToFile" />应该用于包含相同命名空间的文件。

<xsd:import namespace="namespace" schemaLocation="pathToFile" />should be used for include files in a different namespace. Usually you will specify the namespace given as the targetNamespace of the imported schema.

<xsd:import namespace="namespace" schemaLocation="pathToFile" />应该用于包含不同命名空间中的文件。通常,您将指定给定的命名空间作为导入模式的 targetNamespace。

回答by David Norman

Use the <include> element, see for example here.

使用 <include> 元素,请参见此处的示例。