XML:
<?
xml version="1.0"
?>
<? xml-stylesheet href="chrome://global/skin/" type="text/css" ?>
< window id ="example-window" title ="Example 2.7.3"
xmlns:html ="http://www.w3.org/1999/xhtml"
xmlns ="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" >
< html:div >
Would you like to save the following documents?
< html:hr />
</ html:div >
Expense Report 1
What I Did Last Summer
< button id ="yes" label ="Yes" />
< button id ="no" label ="No" />
</ window >
<? xml-stylesheet href="chrome://global/skin/" type="text/css" ?>
< window id ="example-window" title ="Example 2.7.3"
xmlns:html ="http://www.w3.org/1999/xhtml"
xmlns ="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" >
< html:div >
Would you like to save the following documents?
< html:hr />
</ html:div >
Expense Report 1
What I Did Last Summer
< button id ="yes" label ="Yes" />
< button id ="no" label ="No" />
</ window >
这是一段典型的XML代码(XUL)。直观的说,xml是一些被"<>"和"</>"包围的字段对。
优点:
代码可读性较强,标记本身的文法比较简单。具备天然的树形结构。
缺点:
冗余信息比较多,占用带宽。容易造成交叉嵌套,如:<a><b></a></b>。
HAML:
这是针对Rhtml改进而来的一种标记文法。
rhtml:
<
div
id
="profile"
>
< div class ="left column" >
< div id ="date" >< %= print_date % ></ div >
</ div >
< div class ="right column" >
< div id ="email" >< %= current_user .email % ></ div >
< div id ="bio" >< %= h current_user.bio % ></ div >
</ div >
</ div >
< div class ="left column" >
< div id ="date" >< %= print_date % ></ div >
</ div >
< div class ="right column" >
< div id ="email" >< %= current_user .email % ></ div >
< div id ="bio" >< %= h current_user.bio % ></ div >
</ div >
</ div >
这是对应的HAML:
#profile
.left.column
#date = print_date
#address = current_user.address
.right.column
#email = current_user.email
#bio = h(current_user.bio)
.left.column
#date = print_date
#address = current_user.address
.right.column
#email = current_user.email
#bio = h(current_user.bio)
可见其大幅降低了RHtml的信息量。
参考文档:《HAML:简洁高效就是美》
YAML:
这是RUBY使用的配置文件的标记文法。
xml表示:
<?
xml version="1.0"
?>
< club >
< players >
< player id ="kramnik"
name ="Vladimir Kramnik"
rating ="2700"
status ="GM" />
< player id ="fritz"
name ="Deep Fritz"
rating ="2700"
status ="Computer" />
< player id ="mertz"
name ="David Mertz"
rating ="1400"
status ="Amateur" />
</ players >
< matches >
< match >
< Date > 2002-10-04 </ Date >
< White refid ="fritz" />
< Black refid ="kramnik" />
< Result > Draw </ Result >
</ match >
< match >
< Date > 2002-10-06 </ Date >
< White refid ="kramnik" />
< Black refid ="fritz" />
< Result > White </ Result >
</ match >
</ matches >
</ club >
< club >
< players >
< player id ="kramnik"
name ="Vladimir Kramnik"
rating ="2700"
status ="GM" />
< player id ="fritz"
name ="Deep Fritz"
rating ="2700"
status ="Computer" />
< player id ="mertz"
name ="David Mertz"
rating ="1400"
status ="Amateur" />
</ players >
< matches >
< match >
< Date > 2002-10-04 </ Date >
< White refid ="fritz" />
< Black refid ="kramnik" />
< Result > Draw </ Result >
</ match >
< match >
< Date > 2002-10-06 </ Date >
< White refid ="kramnik" />
< Black refid ="fritz" />
< Result > White </ Result >
</ match >
</ matches >
</ club >
对应的YAML表示:
---
players:
Vladimir Kramnik: &kramnik
rating: 2700
status: GM
Deep Fritz: &fritz
rating: 2700
status: Computer
David Mertz: &mertz
rating: 1400
status: Amateur
matches:
-
Date: 2002-10-04
White: *fritz
Black: *kramnik
Result: Draw
-
Date: 2002-10-06
White: *kramnik
Black: *fritz
Result: White
players:
Vladimir Kramnik: &kramnik
rating: 2700
status: GM
Deep Fritz: &fritz
rating: 2700
status: Computer
David Mertz: &mertz
rating: 1400
status: Amateur
matches:
-
Date: 2002-10-04
White: *fritz
Black: *kramnik
Result: Draw
-
Date: 2002-10-06
White: *kramnik
Black: *fritz
Result: White
优点:削除了xml的数据冗余。更接近实际的数据结构。
参考文档:《YAML/5分钟认识》,《XML 问题: YAML 对 XML 的改进》
JSON:
这是从javascript衍生而来的标识方法。其语法接近于javascript的数据结构。
优点:削除了xml的数据冗余性,对数据的定义直观,全面。便于脚本语言处理。
缺点:使用到的标记过多,过分依赖数据结构。层次感,语义感不强。
PYX:
这是最接近xml,也是个人认为最难看的一种标记方式。