一、简介

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

运行

最新文章

  1. .Net Core Linux centos7行—vscode开发,linux部署运行
  2. java命名规范有感
  3. 开源服务专题之------sshd服务安装管理及配置文件理解和安全调优
  4. mustache.js渲染带事件的模板
  5. bios启动过程图解
  6. 查询反模式 - 正视NULL值
  7. USB的四种传输类型与端点
  8. HDP 2.6 requires libtirpc-devel
  9. mysql数据库保存sesison会话
  10. Hadoop 和 MPP 的比较
  11. Qt ------ 添加某个功能,比如(QSerialPort)注意事项
  12. “一切都是消息”--iMSF(即时消息服务框架)之【请求-响应】模式(点对点)
  13. 分组查询以及having使用
  14. C# 当前目录你了解多少
  15. eclipse代码自动提示,eclipse设置代码自动提示
  16. 运行mlflow命令报错 The &#39;nose&#39; distribution was not found and is required by nose-exclude
  17. Java自学-初识
  18. Matplotlib Tutorial(译)
  19. MultipartEntity 乱码
  20. UITextInputMode

热门文章

  1. filter vs servlet
  2. Selenium如何定位动态id的元素?
  3. Tornado之模板
  4. UVA133
  5. tomcat 服务器发布网站
  6. 前端开发-2-HTML
  7. Datatable数据分组
  8. insert NULL into mysql
  9. 数据报表之Excel操作模块
  10. express + mongodb 搭建一个简易网站(二)