C语言HTML解析器

2010-05-21 09:24 / 2 comments / 142 views /

写成一个C语言处理HTML的库。头文件内容如下:
#ifndef _HTML_H
#define _HTML_H
typedef struct tag{
char * name;
char * id;
char * class;
char * val;
int closed;
struct tag * next;
}tag;

extern int openhtml(char * file);
extern tag* gettags();
extern tag* searchclass(char * class);
extern void closehtml();
#endif
使用openhtml打开HTML文件。用gettags得到所有标签列表。
每个标签有name、id和class属性,如果属性为空则指针为NULL。用closed标记该标签是否有结束标志,如<br/>。val指向标签后第一个字节。
如果要打开其它html文件要先用closehtml做内存清理工作。
show一下源代码:html-0.1
希望帮忙测试完善一下。

Tags: .

Get a Trackback link

2 Comments

  1. 无聊2010年5月21日 9:44:

    呵呵,强悍。。

  2. 烂鱼2010年5月22日 19:39:

    支持喽!博客不错!

Leave a comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>