一、简介

YAML是一种人们可以轻松阅读的数据序列化格式,并且它非常适合对动态编程语言中使用的数据类型进行编码。YAML是YAML Ain't Markup Language简写,和GNU("GNU's Not Unix!")一样,YAML是一个递归着说“不”的名字。不同的是,GNU对UNIX说不,YAML说不的对象是XML。YAML不是XML。它可以用作数据序列,配置文件,log文件,Internat信息和过滤。

参考:http://jyaml.sourceforge.net/download.html

http://justjavac.iteye.com/blog/694498

二、安装配置

1)java:下载jar包并导入

2)c:libyaml

方式1:yum方式

yum install libyaml-devel libyaml

方式2:下载libyaml并编译安装

wget http://pyyaml.org/download/libyaml/yaml-0.1.5.tar.gz

tar -zxvf yaml-0.1.5.tar.gz
$ ./configure
$ make
# make install

三、编程实例

参考:http://pyyaml.org/wiki/LibYAML

http://yaml.org/spec/1.1/

程度1:获取yaml版本信息

#include <yaml.h>

#include <stdlib.h>
#include <stdio.h> #ifdef NDEBUG
#undef NDEBUG
#endif
#include <assert.h> int main(void)
{
int major = -1;
int minor = -1;
int patch = -1;
char buf[64]; yaml_get_version(&major, &minor, &patch);
sprintf(buf, "%d.%d.%d", major, minor, patch);
assert(strcmp(buf, yaml_get_version_string()) == 0); /* Print structure sizes. */
printf("sizeof(token) = %d\n", sizeof(yaml_token_t));
printf("sizeof(event) = %d\n", sizeof(yaml_event_t));
printf("sizeof(parser) = %d\n", sizeof(yaml_parser_t)); return 0;
}

编译

gcc -o example1 example1.c -lyaml

运行

程度2:

#include <yaml.h>

#include <stdlib.h>
#include <stdio.h> #ifdef NDEBUG
#undef NDEBUG
#endif
#include <assert.h> int main(int argc, char *argv[])
{
int number; if (argc < 2) {
printf("Usage: %s file1.yaml ...\n", argv[0]);
return 0;
} for (number = 1; number < argc; number ++)
{
FILE *file;
yaml_parser_t parser;
yaml_document_t document;
int done = 0;
int count = 0;
int error = 0; printf("[%d] Loading '%s': ", number, argv[number]);
fflush(stdout); file = fopen(argv[number], "rb");
assert(file); assert(yaml_parser_initialize(&parser)); yaml_parser_set_input_file(&parser, file); while (!done)
{
if (!yaml_parser_load(&parser, &document)) {
error = 1;
break;
} done = (!yaml_document_get_root_node(&document)); yaml_document_delete(&document); if (!done) count ++;
} yaml_parser_delete(&parser); assert(!fclose(file)); printf("%s (%d documents)\n", (error ? "FAILURE" : "SUCCESS"), count);
} return 0;
}

编译

gcc -o example2 example2.c -lyaml

运行

YAML教程的更多相关文章

  1. 学习pyyaml

    网上查了一圈,觉得较好的yaml教程有: YAML 语言教程 :http://www.ruanyifeng.com/blog/2016/07/yaml.html. 另外,在github的pyyaml库 ...

  2. 转: YAML 语言教程 from(阮一峰)

    YAML 语言教程 from: http://www.ruanyifeng.com/blog/2016/07/yaml.html

  3. 转:spring boot log4j2配置(使用log4j2.yml文件)---YAML 语言教程

    转:spring boot log4j2配置(使用log4j2.yml文件) - CSDN博客http://blog.csdn.net/ClementAD/article/details/514988 ...

  4. YAML 语言教程(转载)

    用YAML语言读取配置是最快的,之前的suricata中用yaml读取了配置,并且在代码运行期间,对配置进行了维护,所以抽点时间,来了解一下YAML语言编程,下文虽然对YAML语言和JAVAScrip ...

  5. yaml语言教程

    大家直接去看阮一峰的教程. http://www.ruanyifeng.com/blog/2016/07/yaml.html?f=tt 简介 基本语法规则: 大小写敏感 使用缩进表示层级关系 缩进时不 ...

  6. 学习笔记:yaml语言教程

    目录 1.YAML基本概念 1.1 简介 1.2 基本语法 1.3 支持的数据结构: 1.4 注意点 2.数据结构 2.1 字典 2.2 数组 2.3 纯量 2.4 强制类型转换,双! 2.5 字符串 ...

  7. Spring Boot2 系列教程 (五) | yaml 配置文件详解

    自定义属性加载 首先构建 SpringBoot 项目,不会的看这篇旧文 使用 IDEA 构建 Spring Boot 工程. 首先在项目根目录 src >> resource >&g ...

  8. YAML 语言教程与使用案例

    YAML语言教程与使用案例,如何编与读懂写YAML文件. YAML概要 YAML 是 “YAML Ain’t a Markup Language”(YAML 不是一种标记语言)的递归缩写.在开发的这种 ...

  9. YAML基础教程

    一.YAML介绍YAML参考了其他多种语言,包括:XML.C语言.Python.Perl以及电子邮件格式RFC2822.Clark Evans在2001年5月在首次发表了这种语言,另外Ingy döt ...

随机推荐

  1. collections模块---(namedtuple、deque、OrderdDict、defaultdict、Counter)和configparser模块

    在内置数据类型(dict. list.set.tuple)的基础上,collections模块还提供了几个额外的数据类型:Counter. deque.defaultdict.namedtuple 和 ...

  2. smokeping配置方法

    smokeping配置加Nginx https://lala.im/2821.html  (不完整)

  3. leetcode127

    class Solution { public int ladderLength(String beginWord, String endWord, List<String> wordLi ...

  4. linux 关于数据库的部分命令

    开启数据库服务 service mysqld start 关闭数据库服务 service mysqld stop 链接数据库 mysql -h localhost -u root -p 回车然后输入密 ...

  5. Using Celery with Django

    参考1: http://docs.celeryproject.org/en/latest/django/first-steps-with-django.html#using-celery-with-d ...

  6. eclipse菜单栏工具

    1. new Class 和 new Package 通过右键->new -> 找到java->class 方式太慢. 在window->perspective -> c ...

  7. 10 并发编程-(线程)-GIL全局解释器锁&死锁与递归锁

    一.GIL全局解释器锁 1.引子 在Cpython解释器中,同一个进程下开启的多线程,同一时刻只能有一个线程执行,无法利用多核优势 首先需要明确的一点是GIL并不是Python的特性,它是在实现Pyt ...

  8. vue基础——表单输入绑定

    一.基础用法 你可以用 v-model 指令在表单 <input> 及 <textarea> 元素上创建双向数据绑定.它会根据控件类型自动选择正确的方法来更新元素. 尽管有些神 ...

  9. xcopy 复制目录及子目录

    例:将a文件夹内的所有内容(包括子文件夹)复制到b文件夹 xcopy a\* b /y /e /i /q 说明: /y:不弹出“确认是否覆写已存在目标文件”的提示 /e:复制文件及子文件夹内所有内容, ...

  10. Java HashMap两种遍历方式

    第一种: Map map = new HashMap(); Iterator iter = map.entrySet().iterator(); while (iter.hasNext()) { Ma ...