我可以让一个 XML 架构 (XSD) 包含另一个 XML 架构吗? [英] Can I have one XML Schema (XSD) include another XML-Schema?

查看:23
本文介绍了我可以让一个 XML 架构 (XSD) 包含另一个 XML 架构吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前有两个 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆