下面是一个用在通讯应用程序中的XML事例: <message> <to>you@yourAddress.com</to> <from>me@myAddress.com</from> <subject>XML Is Really Cool</subject> <text> How many ways is XML cool? Let me count the ways... </text> </message>
<message to="you@yourAddress.com" from="me@myAddress.com" subject="XML Is Really Cool"> <text> How many ways is XML cool? Let me count the ways... </text> </message>
可是,有些时候,一个标记独自存在也是可以被理解的。例如,你可能像增加一个“flag”标记,用这个标记来标识信息的重要性。这样的一个标记不包含任何的内容,所以它被称作“空标记”。你可以通过用/>代替>来产生这个空标记的。例如,下面的信息就包含这样的标记: <message to="you@yourAddress.com" from="me@myAddress.com" subject="XML Is Really Cool"> <flag/> <text> How many ways is XML cool? Let me count the ways... </text> </message>
注意: 这个空标记使你不用为了格式良好性而不得不写成<flag></flag>。你可以通过产生一个文档类型定义DTD(Document Type Definition)来控制那个标记可以被置程空标记。我们将在后面讨论DTD。如果没有DTD,那么文档中可以包含任意种类的格式良好的标记 。
XML文件中的注释 XML的注释很像HTML的注释: <message to="you@yourAddress.com" from="me@myAddress.com" subject="XML Is Really Cool"> <!-- This is a comment --> <text> How many ways is XML cool? Let me count the ways... </text> </message>
连接能力 很感谢HTML,在文档之间定义连接的能力现在被认为是不可缺少的。本指南的下一部分,XML and Related Specs: Digesting the Alphabet Soup,讨论了连接规范初步。这个初步使你能够定义双向连接:多目标连接、展开连接(点击一个连接使目标信息内嵌显示)和两文档之间的连接。