首页   关于我们   网站建设   上海兼职网站制作  兼职网站设计  网站案例   网站知识   联系我们   

将html源代码规范化,转换成XSL代码的asp工具_QQread.com

发布于:2007-9-30 已被阅读: 次 来源:上兼职海网站建设

将下面的四个文件存在同一级目录下,再在同目录下建立一个文件txt.txt。当要处理html代码时,先将源代码拷入txt.txt,再进入index_transform.asp,即可看到处理完的代码。写这个东西的本意是因为:经常要对美工用切图软件生成的网页文件转换成xsl,很头疼要花大量的时间去改写不规范的html代码。这个东西对全文所有的html代码进行改动:1.把所有标记都变成小写;2.把标签的属性值都加上双引号;3.把单端标签<hr>、<img……>、<input……>等,改成<hr网站>……;4.把单独属性selected变成:selected="selected";功能不完善之处:对html代码中,属性值内包含空格的情况不能正常处理;对<script>、<style>标签里的不能正常处理。因为是以空格为标志将标签里的各个属性值split成的数组,所以对属性值中包含空格的还没做进一步处理。OK,耽误大家时间了,看看这个东西能派上用场吗?圣诞快乐~! :)===================================================================================================='文件1:transform.asp◎◎◎◎◎◎◎◎◎◎◎◎◎◎◎◎◎<%'*****************************************'Author:小乙'时间:2000.12.20'功能:初步完成对要被转换成XSL文件的:普通html代码语法规范化的功能'运行环境:可运行asp的机子。在同级目录下把要处理的html代码copy到'txt.txt文件里。'***************************************'================================================================================================''''''''''''''''''''''''''''''''制作对全文所有html源代码进行语法规范化】'''''''''''''''''''''''''''''在这个函数里,调用了另外一个主要函数alone_tag,来处理从中摘出来的单个标签。Function transform(txt)dim alltmp    '定义此字符串变量,随着被处理的大字符串减少而减短——只保留未处理的字符串部分。alltmp=txtalltmp=replace(alltmp,"&nbsp;","&#32;")            'nbsp_tmp是替换掉文本中的字符实体&#nbsp;'□■■■■■——进入全文的处理htm源代码的大处理循环——■■■■■□do while trim(alltmp)<>""'msgbox alltmpindex=0index=InStr(1,alltmp,"<",1)'根据index的值,判断"<"前面是否有文本?有:加到txt1;无:进行标签处理(index=1)——即进入标签处理分支if index=1 thenindex_right=InStr(1,alltmp,">",1)tag=left(alltmp,index_right)                '取出alltmp临时串中">"前面的字符串    '对到这里的标签,判断如果标签不是后端标签,就调用处理标签大函数alone_tag    if mid(tag,2,1)<>"网站" then    tag1=alone_tag(tag)    'tag1=tag+",,,,,|"    txt1=txt1+tag1    del_tag=len(tag)    else                    '否则对其它标签,就转为小写后,简单的加在txt1后面    txt1=txt1+LCase(tag)    del_tag=len(tag)    end ifelse    if index>1 then    str_tmp=left(alltmp,index-1)    txt1=txt1+str_tmp                        'index<>1,说明前面有文本。    del_tag=len(left(alltmp,index-1))        '把"<"前面的属于文本的添加到新txt1大字符串中去。    end if    if index=0 then                            '当再也找不到<时(到了末尾),把剩下的字符串全部加到txt1里,结束循环。    txt1=txt1+alltmp    del_tag=len(alltmp)    end ifend if'把处理完的部分从原字符串中减掉'response.write "alltmp="+alltmpalltmp=right(alltmp,len(alltmp)-del_tag)    '(如果标签长大于等于2个字符)这里有问题!12.14,下次再作!!loop''□■■■■■——离开全文的处理htm源代码的大处理循环——■■■■■□'transform=txt1txt1=replace(txt1," ="""" "," ")        '制作这句是对付=""漏网之鱼    2000.12.15txt1=replace(txt1," >",">")            '制作这句是对付 >        2000.12.19txt1=replace(txt1,"<tbody>","")        '制作这句是对付<tbody>    2000.12.19transform=replace(txt1,"<网站tbody>","")        '制作这句是对付<网站tbody>    2000.12.19End Function''''''''''''''''''''''''''''''''制作对全文所有html源代码进行语法规范化,结束】''''''''''''''''''''''''%>===================================================================================================='文件2:index_transform.asp◎◎◎◎◎◎◎◎◎◎◎◎◎◎◎◎◎<%@ Language="VBScript" %><!-- #include file="transform.asp" --><!-- #include file="alone_tag.asp" --><%'-------------------------------------本部分得到全文源代码,开始------------------------------------dim txt        '源文件中的文本dim txt1    '经过html语法规范化后的文件字符串。dim tmpreadline    '=thisfile.readlinetxt="":txt1="":tmpReadAll=""'取得源文件名称,及所在路径-------------sourcefile="txt.txt"sourcefile=Request.form("txtname")'--------------------------新增部分,获得上传文本文件的内容------------2000.12.15'txt=request.form("filecontent")'if len(txt)<>"" then'response.write "---------------"'end if 'response.end'--------------------------新增部分结束------------2000.12.15'-----------------------------------------------------制作正式开始操作文件】----------------------whichfile=server.mappath("txt.txt")'whichfile=server.mappath(sourcefile)Set fs = CreateObject("Scripting.FileSystemObject")Set thisfile = fs.OpenTextFile(whichfile, 1, False)counter=0    tmpReadAll=thisfile.readall                            'ReadAll是读取全部文件内容。    txt=tmpReadAll    txt1=transform(cstr(tmpReadAll))    txt=server.htmlencode(txt)+"    制作文件内容到此结束】"'''''''''''''''''''''''''''''''''''''''''''''''''''''''                                        '如果要看打印出来长字符串的效果,请取消上面这行注释。'-------------------------------------本部分得到全文源代码,结束------------------------------------%><%''''''''''''''''''''''''''''''制作这里正式html页面开始】'''''''''''''''''''''''''''''''''''''''''%><html><head><title>倒数第二版<网站title><meta http-equiv="Content-Type" content="text网站html; charset=gb2312"><网站head><body bgcolor="#BFA49a"><form method="post" action="index_transform.asp" name="form1">  <table border="1" cellspacing="0" cellpadding="5" align="center" bgcolor="#99CCCC" bordercolor="#330066">    <tr>       <td>         <input type="text" name="txtname" value="txt.txt">                 <input type="file" name="filecontent">                 <input type="submit" name="Submit" value="提交">        <a href="#pagedown">到下面<网站a>      <网站td>    <网站tr>  <网站table><网站form> <br><!-------------------页面表单2开始(form2)---------------------><form method="post" action="trans2.asp" name="form2" enctype="multipart网站form-data">   <table width="753" border="1" cellspacing="0" cellpadding="5" align="center" bgcolor="#99CCCC" bordercolor="#330066">    <tr bgcolor="#98AFE7" bordercolor="#FFCC99">       <td bordercolor="#FFFFFF">原文:<网站td>      <td bordercolor="#FFFFFF">处理后:<网站td>    <网站tr>    <tr>       <td>         <textarea name="txt" cols="50" rows="25" onFocus="this.select()" onclick="this.focus()"><%=txt%><网站textarea>      <网站td>      <td>         <%''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''%>        <textarea name="txt" cols="50" rows="25" onFocus="this.select()" onclick="this.focus()"><%=txt1%><网站textarea>      <网站td>    <网站tr>  <网站table>  <div id="Layer1" style="position:absolute; width:68px; height:35px; z-index:1; left: 349px; top: 411px; background-color: #E7E7E9; layer-background-color: #E7E7E9; border: 1px none #000000">     <div align="center">       <input type="submit" name="Submit2" value="提交">      <INPUT TYPE=button NAME="view" VALUE="看源码" OnClick='window.location="view-source:" +window.location.href'>    <网站div>  <网站div><网站form>  <p>&nbsp;<网站p><br><a name="pagedown"><hr size="1" align="center" width="90%" color="#88ff99"><!-------以下是处理完的源代码-----------><%=txt1%><!-------处理完的源代码到此为止-------><网站body><网站html><%'释放资源Erase strtag1Erase strtag2Erase strtag3thisfile.Closeset thisfile=nothingset fs=nothing%>===================================================================================================='文件3:alone_tag.asp◎◎◎◎◎◎◎◎◎◎◎◎◎◎◎◎◎<!-- #include file="func_flag.asp" --><%'tag="<hr bgcolor=""#ccFFFF"" size=4568481,dfafd selected>"'----------------------------进入这里时应该已经得到一个完整的标签--------------------------------'--------在此建立了一个大函数用来处理一个完整的标签里的属性值。一直到页面尾部为止。function alone_tag(tag)dim tag1            '定义处理完以后的标签,并在本函数末尾,将此值返还给alone_tag。tag=LCase(tag)        '将标签命名为tag,并且为了美观,把所有字符串都改写成小写形式'---------到此先准备好标签的自身,以备后面拼回标签的时候使用(减一是因为后面拼属性时把空格加上了)dim tmpattri    '此变量是临时字符串,包含一个标签中的所有属性值,利用它来求“属性数组:attribute”index=InStr(1,tag," ",1)tmpattri=right(tag,len(tag)-index)                '除去左侧标签if len(tmpattri)>1 thentmpattri=trim(left(tmpattri,len(tmpattri)-1))    '除去右侧">",并去除两端空格(如果标签长大于等于2个字符)end iftmpattri=replace(tmpattri,chr(13)," ")    '对源码中,一个标签不在一行里的情况,尚等待另行考虑处理。tmpattri=replace(tmpattri,chr(10)," ")tmpattri=replace(tmpattri,chr(10)&chr(13)," ")tmpattri=replace(tmpattri,"  "," ")        '制作这两句是对付当属性串里有多个空格的时候,tmpattri=replace(tmpattri,"  "," ")        '制作替换成一个空格,不过只能处理不超过16个空格的情况。tmpattri=replace(tmpattri,"  "," ")tmpattri=replace(tmpattri,"  "," ")tmpattri=replace(tmpattri,"  "," ")tmpattri=replace(tmpattri,"  "," ")tmpattri=replace(tmpattri,"  "," ")attribute=Split(tmpattri, " ", -1, 1)    '新定义一个数组,是专为装载属性值而设的。Dim attribute'msgbox "这里得到准备拆分属性数组的长字符串:  "+tmpattri'--------------------到这里已经得到一个关于属性值的数组:attribute-------------------------------'--------『这个循环是处理上面处理完毕的属性值字符数组(attribute)的』-------------------'flag=0:说明单个属性有等于号,且有双引号——语法正常,后面对此标志忽略。    (例:width="325")'flag=1:说明单个属性有等于号,且没有双引号——需要处理,对语法规范化        (例:width=325)'flag=2:说明单个属性没有等于号(例:selected)'flag=3:说明是单端标签,(例:<hr width="80%" size="1">)此语句在前面设标志,并进行处理For count=0 to UBound(attribute, 1)        '一个元素的属性不多.    If InStr(1,attribute(count),"=",1)=0 Then    flag=2                                '单个属性串中没找到等于号。(例:selected)    Else        IF InStr(1,attribute(count),"""",1)=0 Then        flag=1                            '单个属性串中没找到等于号。(例:width=325)        Else        flag=0                            '单个属性串找到了等于号。(例:width="325")            IF InStr(1,attribute(count),"""",1)>0 Then            'attribute(count)=attribute(count)+attribute(count+1)            'attribute(count+1)=""        '这两句是说,把下一个属性串的赋给它,把下一个属性串置为零。            flag=4    '单个属性串找到了等于号,并且包含分号。(例:content="text网站html; charset=gb2312")            End IF        End If    End If'------------------对属性数组,根据上面打的不同标志来调用不同函数进行处理--------------Select case flag        case 0 attribute(count)=attribute(count)        case 1 attribute(count)=func_flag1(attribute(count))    '调用函数func_flag1处理。(例:width=325)        case 2 attribute(count)=func_flag2(attribute(count))    '调用函数func_flag2处理。(例:selected)        case 3 attribute(count)=func_flag3(attribute(count))    '调用函数func_flag3处理单端标签(例:<img…)        case 4 attribute(count)=(attribute(count))                '另行处理属性串之间包含分号、空格的情况End SelectNextcount=0for count=0 to UBound(attribute, 1)attribute_tmp=attribute_tmp+" "+attribute(count)    '属性值之间要有空格next'----------到这里已经把各个符合属性值规范的属性拼成一个串attribute_tmp,下面进行拼标签------index=InStr(1,tag," ",1)    if InStr(1,tag," ",1)=0 and len(tag)<>"" then    '当空格没找到(意味着是空属性值标签),且没有到末尾时。    tag1=Replace(tag,">"," >")            '在此类标签(例<hr>)后尾加上一个空格    else    tag_self=left(tag,index-1)    '拼标签与属性串。    tag1=tag_self+attribute_tmp+">"    end if'msgbox "tag_self"+tag_self'msgbox "(要输出的标签串)tag1ssssssssssss:"+tag1'-----------------到这里已经得到一个属性值规范的标签,但要开始对单端标签进行处理------------'----替换单端标签--------'count=0for count=0 to UBound(strtag3,1)    if InStr(1,tag1,strtag3(count),1)<>0 then    '这里利用到前面已切分好的属性标签    tag1=func_flag3(tag1)                        '对付单端标签——flag=3(例:<img…)    end ifnext'-----------------到这里已经得到一个完全语法规范化的标签。单端标签处理完毕------------alone_tag=tag1end function'<SCRIPT LANGUAGE="javaScript">'<!--'tag='<%=alone_tag(tag)% >''alert (tag)'web-->'<网站SCRIPT>%>===================================================================================================='文件4:func_flag.asp◎◎◎◎◎◎◎◎◎◎◎◎◎◎◎◎◎<%strtag_source1="<html ,<body ,<table ,<td ,<tr ,<option ,<font ,<div ,<span ,<h1 ,<h2 ,<form "strtag1 = Split(strtag_source1, ",", -1, 1)strattri_source2="selected,checked,norwap,readonly,noshade"            '单独属性strtag2 = Split(strattri_source2, ",", -1, 1)strtag_source3="<input ,<img ,<hr ,<br ,<meta"        '单端标签strtag3 = Split(strtag_source3, ",", -1, 1)''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''-------------------以下是处理flag值的多个函数---------制作保留】----开始function func_flag1(tmp)'处理单个属性:(例:width=325)index=InStr(1,tmp,"=",1)z1=left(tmp,index)z2=""""z3=mid(tmp,index+1,len(tmp)-len(z1))func_flag1=z1+z2+z3+z2end functionfunction func_flag2(tmp)'(例:selected)func_flag2=tmp+"="+""""+tmp+""""end functionfunction func_flag3(tmp)'处理单端标签(例:<img…)func_flag3=replace(cstr(tmp),">","网站>")end function'-------------------以上是处理flag值的多个函数---------制作保留】----结束''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''%>进入讨论组讨论。 建设 加密代码和解密代码的html源代码在IE7中快速查看修改网页html源代码在IE7中快速查看网站修改网页html源代码html源代码攻防战 制作

网站建设相关信息

上兼职海网站建设服务

一、网站建设套餐A型
1个英文.COM域名
80M独立网站空间
25M邮件空间,5个企业邮箱
1个FLASH首页,10个精美内页
网站建设优惠价:面谈

二、网站建设套餐B型
1个英文.COM域名
120M独立网站空间,加75M备份,免费Access数据库
50M邮件空间,10个企业邮箱
1个FLASH首页,20个精美内页
1个新闻发布系统
1个计数器,一个留言板
网站建设优惠价:面谈

三、网站建设套餐C型
1个英文.COM域名
250M独立网站空间,加125M备份,免费Access数据库
100M邮件空间,20个企业邮箱
1个FLASH首页,30个精美内页
一个新闻发布系统
一个产品发布系统
1个计数器,一个留言板
网站建设优惠价:面谈

网站知识

什么是网站运营?
网络营销-网站优化
提高博客人气的方法
整站优化要注意平衡
如何为企业的网站建设准备
高难上海兼职网站制作的心得
什么样网页布局是你最喜欢
一个好的网站建设应该
网页设计师的薪水标准
上海兼职网站制作中心对
保持网站建设制作流量