For faster navigation, this Iframe is preloading the Wikiwand page for Canonical XML.

Canonical XML

Canonical XML(规范化形式的XML)XML规范的一个子集。任何XML文档都可以转换为规范化形式的XML,因此将特定类型的微小差异去除却仍是该XML文档。由于这些特定的差异通常不认为是有意义的,转换成规范化形式的XML是判断两个XML文档逻辑上是否是同一个文档的好办法。

举例来说,XML允许在开始标签(tag)的不同点出现,属性可以按任何顺序书写,这些差异很少用来表达含义,因此这些形式通常被认为是相等的

   <p class="a" secure="1">
   <p     secure   = "1"
             class='a'   >

在将一个任意XML文档到规范化形式的XML的转换中,属性将按标准书序(名字的字母顺序)排列,空格和引号被标准化。 这样上面的第二种形式将转换成第一种。

Canonical XML定义了一些规范化形式的规则,包括:

  • 使用UTF-8编码
  • 用0x0A字符表示换行符
  • 属性值里的白空格被正规化
  • 添加缺省属性的说明
  • CDATA标记的部分替换为相应的文字字符
  • 展开实体引用
  • 删除XML的声明和DTD
  • 空元素使用开始/结束标签对,而不是用特殊的空元素语法
  • 属性按照属性名的字母顺序排序
  • 删除元素中多余的命名空间声明

讲一个文档转换为规范化形式的XML是幂等的。 也就是说,第一次转换通常产生与原文档不同的字符串,而重复的转换将不再产生变化。

根据W3C的规范,如果两个XML文档具有相同的规范化形式,那么在一定的应用上下文(极少见的情形除外)中,这两个文档在逻辑上是相等的。

然而,在特殊的上下文中,用户可能关心规范形式的XML逻辑等价之外的特殊语义。比如说,隐写术系统可能在XML文档中通过不同的白空格,属性引号和顺序,使用十进制或十六进制数字字符等等来隐藏信息。显然,将这样的文件转换为标准化形式的XML将丢失这些特殊的语义。而另一方面,XML文件使用大小写的不同,单词使用古代的拼写或现代的拼写等,在某种意义上可以看作是相同的,这样的语境超过了标准化形式XML的范围。

参见

[编辑]

外部链接

[编辑]
{{bottomLinkPreText}} {{bottomLinkText}}
Canonical XML
Listen to this article

This browser is not supported by Wikiwand :(
Wikiwand requires a browser with modern capabilities in order to provide you with the best reading experience.
Please download and use one of the following browsers:

This article was just edited, click to reload
This article has been deleted on Wikipedia (Why?)

Back to homepage

Please click Add in the dialog above
Please click Allow in the top-left corner,
then click Install Now in the dialog
Please click Open in the download dialog,
then click Install
Please click the "Downloads" icon in the Safari toolbar, open the first download in the list,
then click Install
{{::$root.activation.text}}

Install Wikiwand

Install on Chrome Install on Firefox
Don't forget to rate us

Tell your friends about Wikiwand!

Gmail Facebook Twitter Link

Enjoying Wikiwand?

Tell your friends and spread the love:
Share on Gmail Share on Facebook Share on Twitter Share on Buffer

Our magic isn't perfect

You can help our automatic cover photo selection by reporting an unsuitable photo.

This photo is visually disturbing This photo is not a good choice

Thank you for helping!


Your input will affect cover photo selection, along with input from other users.

X

Get ready for Wikiwand 2.0 🎉! the new version arrives on September 1st! Don't want to wait?