【问题标题】:Including documentation of element type into XML Schema element?在 XML Schema 元素中包含元素类型的文档?
【发布时间】:2021-06-28 18:39:06
【问题描述】:

您能否将 XML Schema 类型的文档包含在元素的文档中?例如,对于下面的架构,FirstOption 元素的文档应该或多或少类似于:

Enable First Option?

Yes/No Choice
1 = Yes
0 = No
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:simpleType name="MyChoice">
    <xs:annotation>
      <xs:documentation>Yes/No Choice</xs:documentation>
    </xs:annotation>
    <xs:restriction base="xs:string">
      <xs:enumeration value="1">
        <xs:annotation><xs:documentation>Yes</xs:documentation>
        </xs:annotation>
      </xs:enumeration>
      <xs:enumeration value="0">
        <xs:annotation>
          <xs:documentation>No</xs:documentation>
        </xs:annotation>
      </xs:enumeration>
    </xs:restriction>
  </xs:simpleType>
  <xs:element name="Options" >
    <xs:complexType>
      <xs:sequence>
        <xs:element name="FirstOption" type="MyChoice">
          <xs:annotation>
            <xs:documentation>Enable First Option?</xs:documentation>
            <!-- What to write here, to include the documentation of `MyChoice`? -->
          </xs:annotation>
        </xs:element>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>

【问题讨论】:

    标签: xml xsd documentation


    【解决方案1】:

    不,没有标准的、基于 XSD 的方式来自动包含或从另一个组件的文档或结构派生组件的文档。

    • 可能会考虑编写 XSLT 以从 XSD 生成文档,但考虑到所涉及的复杂性,在一般情况下这样做的好处可能有限。1

    另请参阅: XML / XSD - Adding descriptions

    1 我在 XSLT 中构建了一个自动化文档系统,该系统记录了另一个用 XSLT 编写的系统,但手写文档更为常见。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-07-05
      • 1970-01-01
      • 1970-01-01
      • 2010-09-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多