完善自己的html parse
说来惭愧,我发现自己写的那个html parse过于理想化,解析xml还差不多,想解析现今的html,估计是不大可能的,所以我把代码重写了一遍,数据结构改成双向链表,这样解析速度更快,最大程度地对html进行容错处理,试验时发现的确可以解析普通html字符串,不需要再严格符合那个xhtml标准了。而且在链式调用的传递参数上不需要再传入dom类型的参数,这样写起来就更加简便了。
好了,废话不多说,看代码:
#include<iostream>
using namespace std;
class node;
class dom;
class nodecollect{
private:
node *n;
int length;
public:
nodecollect();
~nodecollect();
int getlength();
void add(node *nn);
node* item(int i);
};
class node{
private:
int start;
int len;
char name[20];
public:
char* nodehtml();
char* innerhtml();
char* outerhtml();
char* innertext();
char* getattr(char* str);
char* tagname();
void setname(char *str);
node* getparent();
nodecollect* getchild();
node* getnext();
node* getprevious();
node *next;
node *previous;
void setstart(int i);
void setlen(int i);
int getstart();
int getlen();
dom *d;
};
class dom{
private:
char *text;
node *start;
node *end;
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){
start=0;
end=0;
count=0;
int l=strlen(str);
text=new char[l+1];
strcpy(text,str);
char *t=text;
parse(t);
}
int dom::getcount(){
return count;
}
char *dom::gettext(){
return text;
}
node* dom::getitem(int i){
node* n1=start;
while(i--){
&
相关文档:
例如从1.html跳转到2.html:
在1.html中:
<form name="loginForm" action="2.htm?pageid=1&str='s'" method="post">
当页面提交跳转到2.html中:
<script type="text/javascript">
<!--
var str = location.search;
//-->
&l ......
CSDN博客:http://writeblog.csdn.net/PostList.aspx
方法一:用记事本打开index.htm,替换:10pt ---> 12pt,保存后,用IE打开此htm,ctrl+a--ctrl+c,粘贴到博客就行了!
方法二:在csdn发表文章时,选择【图像】后面的【HTML】按钮,再把index.htm源码粘贴上去,什么也不用改动! ......
HTML元素及控件事件一览表
一般事件
事件
浏览器支持
描述
onClick
HTML: 2 | 3 | 3.2 | 4
Browser: IE3 | N2 | O3
鼠标点击事件,多用在某个对象控制的范围内的鼠标点击
onDblClick
HTML: 2 | 3 | 3.2 | 4
Browser: IE4 | N4 | O
鼠标双击事件
onMouseDown
HTML: 2 | 3 | 3.2 | 4
Browser: IE4 | N4 ......
StringBuilder sb = new StringBuilder();
Server.Execute("~/Default2.aspx", new StringWriter(sb));
File.WriteAllText(Server.MapPath("index.htm"), sb.ToString()); ......