当前位置: 首页 > 图文教程 > 网络编程 > ASP > 在ASP中使用类

ASP
asp查询xml的代码 不刷新页面查询的方法
ASP 快速执行动态网页
asp实现本周的一周时间列表的代码
asp get和post数据接收过滤
为google量身定做的sitemap生成代码asp版
适合所有网站的rss和xml聚合功能asp代码
ASP MSSQL存储过程的实现小例
动网论坛的asp 数据库连接代码
ASP+MSSQL2000 数据库被批量注入后的解决方法
asp 去掉html中的table正则代码函数
asp 过滤非法字符函数
asp检测是否为中文字符函数
ASP 包含文件中的路径问题和使用单一数据库连接文件的解决方案
asp HTTP 500错误 常见问题分析
asp 关键词高亮显示(不区分大小写)
一段ASP的HTTP_REFERER判断代码
asp datediff 时间相减
asp下去除超链接的函数
asp连接mssql2005的代码
asp access数据库并生成XML文件范例

在ASP中使用类


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-11-03   浏览: 125 ::
收藏到网摘: n/a

  VBScript5中增加了许多新功能,最振奋人心的当属类和正则表达式的出现。以下是本人写的一个解析html代码的类。我是
学php的,语法有不习惯的地方,请大家多包含。

<%
Class HTMLParse

    ' 设置 Initialize 事件。
    Private Sub Class_Initialize
        myGlobal = True
        myIgnoreCase = True
    End Sub

    Property Let Global(g)
    Dim regEx            ' 建立变量。
  Set regEx = New RegExp         ' 建立正则表达式。
  regEx.Pattern = "True|False|1|0"         ' 设置模式。
  regEx.IgnoreCase = True         ' 设置是否区分大小写。
  If regEx.Test(CStr(g)) Then
        myGlobal = g
    Else
        Call Halt("无效Global参数配置")
    End If    
    End Property

    Property Get Global()
        Global = myGlobal
    End Property

    Property Let IgnoreCase(c)
    Dim regEx
  Set regEx = New RegExp
  regEx.Pattern = "True|False|1|0"
  regEx.IgnoreCase = True  
  If regEx.Test(CStr(c)) Then
        myIgnoreCase = c
    Else
        Call Halt("无效IgnoreCase参数配置")
    End If
    End Property

    Property Get IgnoreCase()
        IgnoreCase = myIgnoreCase
    End Property

    '解析所有HTML标记的函数
    Public Function Parse(input)
        Parse = "<table border=1 width=50% align=center>" & vbCrLf
        Dim regEx , regVal , match , i
        
        Set regEx = New RegExp
        regEx.Pattern = "<([a-z]\w*)(?:.*?)>(.*)<\/\1>"
        regEx.Global = myGlobal
        regEx.IgnoreCase = myIgnoreCase
        
        Set regVal = regEx.Execute(Trim(input))
        If regVal.Count > 0 Then '如果发现匹配元素
            Parse = Parse & "<caption>发现" & regVal.Count & "个HTML标记</caption>" & vbCrLf
            Parse = Parse & "<tr align=center><th>编号</th><th>匹配标记<th>匹配显示</th></tr>" & vbCrLf
        For i=0 To regVal.Count-1
            Set match = regVal(i)
            Parse = Parse & "<tr align=center>" & vbCrLf
            Parse = Parse & "<td>" & i+1 & "</td&