我可以让一个 XML 架构 (XSD) 包含另一个 XML 架构吗? [英] Can I have one XML Schema (XSD) include another XML-Schema?
问题描述
我目前有两个 XSD 方案,一个是另一个的轻量级"版本.现在我在完整"模式中重复了轻"版本中的所有内容,但是当我需要进行更改时这会变得很痛苦,并且无论如何它都违反了 DRY 原则,所以我想知道是否有一个元素这有助于将另一个架构包含到架构中,因此我可以让我的完整"继承自轻"架构以减少维护障碍.
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:include schemaLocation="pathToFile"/>
应该用于包含相同命名空间的文件.
<xsd:include schemaLocation="pathToFile" />
should be used for including files of the same namespace.
<xsd:import namespace="namespace" schemaLocation="pathToFile"/>
应该用于包含不同命名空间中的文件.通常你会将给定的命名空间指定为导入模式的 targetNamespace.
<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.
这篇关于我可以让一个 XML 架构 (XSD) 包含另一个 XML 架构吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!