初探YAML2005-10-06
YAML何许物也?在XML泛滥的情况下,YAML的出现的确让人眼前一亮,在初步学习了YAML以后,粗略的总结了一下,拿出来和大家分享。[MindMap][参考文档]YAML Specification YAML 数据类型说明[摘要]YAML的设计目的YAML描述: [注释, 文档, 数据结构, 数据类型, 其他]
YAML的设计目的1、容易人类阅读2、适合表示程序语言的数据结构3、可用于不同程序间交换数据4、支持泛型工具5、支持串行处理?6、丰富的表达能力和可扩展性7、易于使用粗看了specification以后感觉最好的是“容易人类阅读”,对比一下下面的xml和yaml的代码块:# xml代码块:
# YAML代码块
或:
YAML利用缩进或者是explicit indicatior(如上面的{})来表示属性的嵌套,更为直观和simple。
YAML描述
先来看看YAML里的主要标记:(1)注释:举个例子:# Comment Example# Profile Of MaryMary: - name: Mary - age : 19 # age property(2)文档(document):现在还不明白文档是什么意思,既然YAML定义是data serialization,暂时把一个doucment视为一个object序列化后得到的yaml配置信息
(3)数据结构:YAML的设计者认为在配置文件中所要表达的数据内容有三种类型:标量(Scalar,如字符串和整数等)、序列(Sequence,如数组)和Mapping(类似hash的key/value pair)。sequence型主要是用来表示数组类型的数据。下图描述了YAML中Sequence型数据的表示法:mapping数据类型主要用来表示key: value对类型的数据。YAML描述方式见下图:最后,我们用YAML来描述一本书《单元测试知道-c#版》
YAML推荐使用空格作为缩进,避免了在不同编辑器中对tab的表示形式不同而可能产生误解。
All the posts in this blog are provided "AS IS" with no warranties, and confer no rights. Except where otherwise noted, content on this site is licensed under a Creative Commons Attribution 2.5 China Mainland License.
对一个问题或领域,从不了解到了解,从了解到熟悉,从熟悉到精通,这记录了K.K思考和解决问题的成长过程。
On an issue or area, never learned to understand, from the learned to be familiar with, from the familiar to the master, this blog records the K.K's growth by thinking and solving problems.
Contact
QQ: 29665625
you can also find me on