易截截图软件、单文件、免安装、纯绿色、仅160KB

c++编写html文件解析器

      最近本来是要去那嵌入式课的,但是那课竟然说人数太少,开不了,靠。所以这两天只能自己研究点东西了。记得自己以前就想动手写一个关于dom的解析引擎,只怪自己太懒,一直没动笔。最近在家也没什么事做,就自己动手写一个,花了一天时间写的差不多了,正好锻炼自己的c++水平吧。
      这个解析程序有三个类,node,nodecollect,dom。dom这个类是个包装,它就相当与document吧,nodecollect是节点的集合,比如getelementsbytagname的返回集合吧,node类就是具体到节点。这个程序解析的原理就是解析一段html字符串,在里面提取节点,然后用链表存储节点,node类有两个私有对象,start,len。start就是该节点字符串到原始字符串的位置,len即使该节点字符串的长度。所以我们根据该节点的start和len就可以定位该节点在原始字符串的位置。
      好了,下面看代码:
#include<iostream>
using namespace std;
class node;
class dom;
class nodecollect{
private:
 node *n;
 int length;
public:
 nodecollect();
 ~nodecollect();
    int getlength();
 node* item(int i);
 void add(node *nn);
 
};
class node{
private:
 int start;
 int len;
public:
 char* innerhtml(dom& d);
 char* outerhtml(dom& d);
 char* innertext(dom& d);
 char* getattr(dom& d,char* str);
 char* tagname(dom& d);
 node* getparent(dom &d);
 nodecollect* getchild(dom &d);
node* getnext(dom &d);
 node* getprevious(dom &d);
 node *next;
 void setstart(int i);
 void setlen(int i);
 int getstart();
 int getlen();
};
class dom{
private:
 char *text;
 node *n;
 int count;
 int parse(char *s);
public:
 ~dom();
 char *gettext();
 void load(char *str);
 node* getitem(int i);
 int getcount();
 node *getbyid(char* id);
 nodecollect* getbytagname(char *tagname);
};
void dom::load(char* str){
 n=0;
 count=0;
 int l=strlen(str


相关文档:

航空公司管理系统(VC++ 与SQL 2005)

系统环境:Windows 7
软件环境:Visual C++ 2008 SP1 +SQL Server 2005
本次目的:编写一个航空管理系统
      这是数据库课程设计的成果,虽然成绩不佳,但是作为我用VC++ 以来编写的最大程序还是传到网上,以供参考。用VC++ 做数据库设计并不容易,但也不是不可能。以下是我的程序界面,后面 ......

高质量 C/C++编程笔记

高质量C++编程 Note
定义1:能长期稳定地编写出高质量程序的程序员称为编程老手。
定义2:能长期稳定地编写出高难度、高质量程序的程序员称为编程高手。
版权和版本的声明位于头文件和定义文件的开头 ,主要内容有:
(1)版权信息。
(2)文件名称,标识符,摘要。
(3)当前版本号,作者/修改者,完成日期。
......

html 获得浏览器高度

有时页面需要获得用户浏览器的高度才能确定内容显示在哪里,代码
<div style="position:absolute; left:0; top:expression(document.body.clientHeight/2-document.body.clientHeight/4)">
</div>
中,expression(document.body.clientHeight/2)即为获得浏览器高度再除以2 ......

将aspx页面转换为html页面

        StringBuilder sb = new StringBuilder();
        Server.Execute("~/Default2.aspx", new StringWriter(sb));
        File.WriteAllText(Server.MapPath("index.htm"), sb.ToString()); ......

在winform中解析html标签

  最近在弄公司的系统时遇到一个问题,有一个winform要调用网站的数据库,数据库中存的是经过eWebEditor处理过的文章,都带有html标签,当时想用正则表达式过滤掉,但是还是放弃了原因有三:1.我对正则表达式了解很少;2.虽说我可以现学正则表达式,但是实现起来也是很麻烦的;3.如果过滤掉的话文章的格式就没有了。于 ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号