我们正在创建符合以下 xsd 的 xml 文件:http://www.topografix.com/gpx/1/1/gpx.xsd此 xsd 支持“...通过在此处添加您自己的元素进行扩展...”,请参阅 extensionsType,为了方便起见,我在下面复制了它。
1) 我不明白注释和文档是否是出现在兼容 xml 中的文字元素名称。我相信他们不是,但需要确认。我假设一个合规文档将在任何 [extensions] 元素内的任何位置简单地包含任意数量的我们自己的自定义元素,对吗?
2) 为什么会有 两个下面成对的注释/文档元素,其中一个是一个序列?
<xsd:complexType name="extensionsType">
<xsd:annotation>
<xsd:documentation>
You can add extend GPX by adding your own elements from another schema here.
</xsd:documentation>
</xsd:annotation>
<xsd:sequence>
<xsd:any namespace="##other" processContents="lax" minOccurs="0" maxOccurs="unbounded">
<xsd:annotation>
<xsd:documentation>
You can add extend GPX by adding your own elements from another schema here.
</xsd:documentation>
</xsd:annotation>
</xsd:any>
</xsd:sequence>
</xsd:complexType>
最佳答案
1) 来自 XML 架构 specification :“注释提供了针对人类和机器的模式组件注释。”模式作者使用 xsd:documentation 作为,比如 Java 或 .NET,开发人员使用注释。
注释是 XML 模式工件;它们不会出现在 XML 文档中。是的,你的扩展元素应该放在
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<!-- Sample XML generated by QTAssistant (http://www.paschidev.com) -->
<gpx xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.1" creator="creator1" xmlns="http://www.topografix.com/GPX/1/1">
<extensions>
<my:element xmlns:my="urn:tempuri-org:some">Hello!</my:element>
</extensions>
</gpx>
2)很难说为什么有两个相同的评论;但区别在于,一个记录复杂类型,而另一个记录 xsd:any 元素。我个人会使用不同的注释,首先解释复杂类型的用途,第二个如图所示。
关于XSD 注释和文档元素,以及如何使用它们,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8187193/