Linux 下配置Expat解析XML

2021-04-21 21:50:27 字數 1912 閱讀 4141

qt中文論壇

下配置expat

解析xml

環境:ubuntu-7.10.ext3.2gb1.fs

資料報:1、

安裝:①

解壓expat-2.0.1.tar.gz

到expat-2.0.1 ②

進入expat-2.0.1/src/

執行./configure ③

進入expat-2.0.1/src/

執行make ④

進入expat-2.0.1/src/

執行make install ⑤

進入expat-2.0.1/src/example

執行nano test.xml

abc123456

⑥進入expat-2.0.1/src/example

執行nano mytest.c

#include

#include

#include

#include

#include

#define length 100

static void xmlcall startelement(void *userdata, const char *name, const char **atts)

printf("%s/n",name);

*depthptr += 1;

}static void xmlcall endelement(void *userdata, const char *name)

static void xmlcall chardata( void *userdata, const xml_char *s, int len)

main()

fd = open("test.xml", o_rdwr);

len = read(fd, buf, length); /**/

buf[len] = '/0';

//printf("%s/n", buf);

close(fd);

xml_parser parser = xml_parsercreate(null);

xml_setuserdata(parser, &depth);

xml_setelementhandler(parser, startelement, endelement);

xml_setcharacterdatahandler(parser,chardata);

do }while (!done);

xml_parserfree(parser);

return 0;}

⑦進入expat-2.0.1/src/example

執行nano makefile

objects = mytest

$(objects):$(objects).o

gcc -o $(objects) $(objects).o

/usr/local/lib/libexpat.so

$(objects).o:

clear:

rm $(objects).o $(objects)

⑧進入expat-2.0.1/src/example

執行make

執行./mytest

Linux下解析配置檔案

配置檔案在linux下使用得非常普遍。形如下面的這個檔案就是乙個典型的配置檔案 this is just an example there can be comments before the first group first group name key file exampletthis va...

Linux下解析配置檔案

配置檔案在linux下使用得非常普遍。形如下面的這個檔案就是乙個典型的配置檔案 this is just an example there can be comments before the first group first group name key file exampletthis va...

linux 下 ifcfg ethx配置和解析

網路介面配置檔案 root localhost cat etc sysconfig network scripts ifcfg eth0 intel corporation 82545em gigabit ethernet controller copper type ethernet 網絡卡型別 ...