Canonical XML
此條目目前正依照其他维基百科上的内容进行翻译。 (2010年7月22日) |
Canonical XML(规范化形式的XML) is a profile or subset of XML。任何XML文档都可以转换为规范化形式的XML,thus normalizing away specific kinds of minor differences while remaining an XML document. Because those specific differences are generally not considered to be "meaningful", converting to Canonical XML is a good way to determine whether two XML documents are logically "the same document" despite differences of detail.
举例来说,XML允许在开始标签(tag)的不同点出现,属性可以按任何顺序书写,Such differences are seldom if ever used to convey meaning, 因此这些形式通常被认为是相等的
<p class="a" secure="1">
<p secure = "1" class='a' >
在将一个任意XML文档到规范化形式的XML的转换中,属性将按标准书序(名字的字母顺序)排列,空格和引号被标准化。 这样上面的第二种形式将转换成第一种。
Canonical XML还说明了一些其他细节,其中的一些是:
- 使用UTF-8编码
- 用0x0A字符表示换行符
- 属性值里的白空格被正规化
- 展开实体引用
- CDATA标记的部分替换为相应的文字字符
- 空元素使用开始/结束标签对,而不是用特殊的空元素语法
- 添加缺省属性的说明
- 删除元素中多余的命名空间声明
讲一个文档转换为规范化形式的XML是幂等的。 也就是说,第一次转换通常产生与原文档不同的字符串,而重复的转换将不再产生变化。
根据W3C的规范,如果两个XML文档具有相同的规范化形式,那么在一定的应用上下文(极少见的情形除外)中,这两个文档在逻辑上是相等的。
然而,在特殊的上下文中,users might care about special semantics beyond the generic logical equivalence with which Canonical XML is associated. For example, a steganography system could conceal information in an XML document by varying whitespace, attribute quoting and order, the use of hexadecimal vs. decimal numeric character references, and so on. Obviously converting such a file to Canonical XML would lose those specialized semantics. On the other hand, XML files that differ in their use of upper- vs. lower-case, or that use archaic versus modern spelling, and so on, might be considered equivalent for certain purposes. Such contexts are beyond the scope of Canonical XML.