XSD注释和文档元素,以及如何使用它们

bet*_*oys 4 xsd

我们正在创建我们希望符合以下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>
Run Code Online (Sandbox Code Playgroud)

Pet*_*dea 8

1)来自XML Schema 规范:"Annotations提供了模式组件的以人和机器为目标的注释." 架构作者使用xsd:documentation,比如Java或.NET,开发人员使用注释.

注释是XML Schema工件; 它们不会出现在XML文档中.是的,您的扩展元素应位于<extensions />; 您可以使用除http://www.topografix.com/GPX/1/1之外的任何命名空间

显示扩展元素的示例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> 
Run Code Online (Sandbox Code Playgroud)

2)很难说为什么有两个有相同的评论; 但不同的是,一个文档是复杂类型,另一个是xsd:any元素.我个人会使用不同的评论,首先解释复杂类型的含义,第二个如图所示.