XMLSchema 注解
注解
在XML文档中提供附加信息的通常方式是使用注释,即在"<!--"和"-->"之间给出注释信息。在XML Schema中,注释仍然可以使用,不过为了方便其他读者和应用程序来理解模式文档,XML Schema提供了三个元素来为模式提供注解。这三个元素是:xs:annotation、xs:documentation和xs:appinfo,其中xs:documentation和xs:appinfo是作为xs:annotation元素的子元素使用的。xs:documentation元素用于放置适合人阅读的信息,而xs:appinfo元素则用于为工具、样式表和其他应用程序提供信息。
我们看例4-32。
例4-32 hr.xsd
<?xml version="1.0" encoding="GB2312"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:annotation> <xs:documentation xml:lang="zh"> 这是一份用于企业雇员信息描述的模式文档 </xs:documentation> </xs:annotation> <xs:element name="hr"> <xs:annotation> <xs:documentation xml:lang="zh"> hr元素是文档的根元素,使用匿名类型定义来声明 </xs:documentation> </xs:annotation> <xs:complexType> <xs:annotation> <xs:documentation xml:lang="zh"> 根元素hr下可以有多个employee子元素 </xs:documentation> </xs:annotation> <xs:sequence> <xs:element name="employee" maxOccurs="unbounded"/> </xs:sequence> </xs:complexType> </xs:element> </xs:schema> |
xs:annotation元素常常在元素声明或类型定义的开头使用,用于对元素的作用、类型的定义提供附加的描述信息。为了说明这些描述信息所使用的语言,可以在xs:documentation元素上使用xml:lang属性来指定语言,xml:lang属性的值是在IETF RFC 3066(Tags for the Identification of Languages)或它的后继版本中定义的语言标识符。
xs:appinfo元素用于为计算机自动处理提供信息,它没有且也不需要xml:lang属性。xs:annotation元素和xs:appinfo元素还有一个可选的source属性,它的值是一个URI引用,指向一个包含了描述信息的文档位置。