如何解决将元素类型的文档包含到 XML 架构元素中?
您能否将 XML 模式类型的文档包含到元素的文档中?例如,对于下面的架构,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>
解决方法
不,没有基于 XSD 的标准方法来自动包含或从另一个组件的文档或结构中派生出一个组件的文档。
- 人们可能会考虑编写 XSLT 以从 XSD 生成文档,但鉴于所涉及的复杂性,在一般情况下这样做的好处可能有限。1
另见: XML / XSD - Adding descriptions
1 我用 XSLT 构建了一个自动化文档系统,它记录了另一个用 XSLT 编写的系统,但手写文档更常见。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。