如何最好地使用 XSD 文件来存储多个模式的通用定义

问题描述

我有多个具有通用定义的 XML 模式。我想将这些定义存储在我们称之为 Common.xsd 的公共文件中。我已经在其他架构中成功引用了 guid 类型。

我不需要,也不希望文件类型 .common 存在。我还没有找到一种方法(例如属性)来确保这是不允许的,并且 Common.xsd 中定义的任何内容都只能从那里继承。

示例

Common.xsd

<?xml version="1.0" encoding="utf-8"?>
<xs:schema
    targetNamespace="MyAssembly:Core:IO:Schemas"
    elementFormDefault="qualified"
    xmlns="MyAssembly:Core:IO:Schemas"
    xmlns:mstns="MyAssembly:Core:IO:Schemas"
    xmlns:xs="http://www.w3.org/2001/XMLSchema">

  <xs:simpleType name="guid">
    <xs:annotation>
      <xs:documentation xml:lang="en-us">
        The representation of a GUID,generally the id of an element.
      </xs:documentation>
    </xs:annotation>
    <xs:restriction base="xs:string">
      <xs:pattern value="\{[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}\}"/>
    </xs:restriction>
  </xs:simpleType>

</xs:schema>

我希望这会像在模式中声明类型一样简单。基本上我在这里谈论的是一个抽象模式,例如:

<xs:schema abstract="true">

</xs:schema>

为了澄清,我确实明白这不是它的工作原理,但我正在寻找最接近的方法来确保 .commmon 文件不被允许或被声明。 >

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)