XML information class Version 1.0

2016-02-19 19:01 15 1 收藏

生活已是百般艰难,为何不努力一点。下面图老师就给大家分享XML information class Version 1.0,希望可以让热爱学习的朋友们体会到设计的小小的乐趣。

【 tulaoshi.com - Web开发 】

%
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''
''''  xml information Class Version 1.0
''''
''''  Author: Xinsoft [ Xin Yaping ]
''''  Email:  XinsoftATk65.net
''''  Xinsoft , 2005-04-28 Xinsoft DevStudio
''''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
%%

(本文来源于图老师网站,更多请访问http://www.tulaoshi.com/webkaifa/)

Class xmlInfo

   Public encoding     '' as String
 
   Public NodeCount
   Public NodeArray
 
   Private xmlURL      '' as String
   Private xmlDoc      '' as Msxml2.DOMDocument.4.0
 
   Private ReadyState  '' as Integer
   Private Status      '' as Integer
   Private LoadSuccess '' as Bool
   Private parseError  '' as Integer
 
   Private curSingleNode   '' as Node
   Private curNodeList     '' as Node List
   Private curXpath        '' as XPath


Private Sub Class_Initialize
   xmlURL=""
   encoding="GB2312"
   NodeCount=0
 
   ReadyState=0
   Status=0
   LoadSuccess=False
   parseError=0
 
   Set xmlDoc = CreateObject("Msxml2.DOMDocument.4.0")
End Sub
Private Sub Class_Terminate
   Set xmlDoc = Nothing
 
   If True = IsObject(NodeArray) Then
       Set NodeArray = Nothing
   End If
   If True = IsObject(curSingleNode) Then
       Set curSingleNode = Nothing
   End If
   If True = IsObject(curNodeList) Then
       Set curNodeList = Nothing
   End if
End Sub

Function BytesToBstr(strBody,CodeBase)
       dim objStream
       Set objStream = Server.CreateObject("Adodb.Stream")
       objStream.Type = 1
       objStream.Mode = 3
       objStream.Open
       objStream.Write strBody
       objStream.Position = 0
       objStream.Type = 2
       objStream.Charset = CodeBase
       BytesToBstr = objStream.ReadText
       objStream.Close
       Set objStream = Nothing
End Function

Public Function httpGet()
   
     Dim Cont
     Dim objXMLHttp
   
     Set objXMLHttp=Server.CreateObject("Msxml2.XMLHTTP")
   
     objXMLHttp.open "GET",xmlURL,False
     objXMLHttp.send()
   
     ReadyState = objXMLHttp.readyState
     Status = objXMLHttp.status
   
     If 4=ReadyState And 200=Status Then
           Cont=objXMLHttp.responseBody
     Else
           Cont=""
     End If
   
     Set objXMLHttp=Nothing
   
     Cont=BytesToBstr(Cont,encoding)
   
     httpGet=Cont
End Function

Public Sub PrintParseErrorInfo()
   If parseError = 1 Then
      
       Response.Write "PSome error found in your xml document./P"
      
       Dim xPE
       Set xPE = xmlDoc.parseError
      
       Response.Write "pxmlDoc.parseError.reason = "& xPE.reason &"/p"
       Response.Write "pxmlDoc.parseError.filepos = "& xPE.filepos &"/p"
       Response.Write "pxmlDoc.parseError.line = "& xPE.line &"/p"
       Response.Write "pxmlDoc.parseError.linepos = "& xPE.linepos &"/p"
       Response.Write "pxmlDoc.parseError.srcText = "& xPE.srcText &"/p"
       Response.Write "pxmlDoc.parseError.URL = "& xPE.URL &"/p"
      
       Set xPE = Nothing
      
   Else
       Response.Write("")
   End if
End Sub

Property Let url( xmlSourceHttp )

   Dim Cont
 
   xmlURL=xmlSourceHttp
 
   xmlDoc.async = False
   xmlDoc.validateOnParse = False
 
   Cont = httpGet()
   LoadSuccess = xmlDoc.LoadXML(Cont)
   ReadyState = xmlDoc.ReadyState
 
   If xmlDoc.parseError.errorCode 0 Then
       parseError = 1
   Else
       parseError = 0
   End If
 
   ''//If True = LoadSuccess Then
   ''//End If

End Property

Property Get url()
   url=xmlURL
End Property

Property Let Xpath( path )
   curXpath=path
End Property
Property Get Xpath()
   Xpath=curXpath
End Property

Property Let SingleNode( Xpath )
   curXpath=Xpath
   Set curSingleNode=xmlDoc.documentElement.selectSingleNode( curXpath )
End Property
Property Get SingleNode()
   Set SingleNode=curSingleNode
End Property

Property Let NodeList( Xpath )
   Dim i
 
   curXpath=Xpath
   Set curNodeList=xmlDoc.documentElement.selectNodes( curXpath )
 
   NodeCount=curNodeList.length
   ReDim NodeArray(NodeCount)
   For i=0 To NodeCount-1
       Set NodeArray(i)=curNodeList.item(i)
   Next
 
End Property
Property Get NodeList()
   Set NodeList=curNodeList
End Property

Property Get loadStat()
   loadStat=LoadSuccess
End Property

Public Function getChildNodeValByName( objNode , ChiidNodeName )
   getChildNodeValByName=objNode.selectSingleNode(ChiidNodeName).text
End Function

Property Get ChildValInList( index , ChildName )
   ChildValInList=getChildNodeValByName( NodeArray(index) , ChildName )
End Property

Property Get ChildVal( ChildName )
   ChildVal=getChildNodeValByName( curSingleNode , ChildName )
End Property

Property Get NodeVal( Xpath )
   NodeVal=xmlDoc.documentElement.selectSingleNode( Xpath ).text
End Property

Property Get XpathNodesLength( Xpath )
   XpathNodesLength=xmlDoc.documentElement.selectNodes(Xpath).length
End Property

Property Get NodeValInList( Xpath , index )
   NodeValInList=xmlDoc.documentElement.selectNodes(Xpath).item(index).text
End Property

End Class

%

(本文来源于图老师网站,更多请访问http://www.tulaoshi.com/webkaifa/)

  XML information Class Version 1.0 调用示范

% option explicit %
!-- #include file="../../lib/xml.asp" --
%
Dim Str,i,N

Dim objXML
Set objXML = New xmlInfo

With objXML
   .url="http://210.77.146.223/tech/indexxml.php";
   .encoding="gb2312"
End With

objXML.NodeList="/blogtech/item"
Response.Write "pobjXML.RecN="&objXML.NodeCount&"/p" & vbCrLf

For i=0 To objXML.NodeCount-1
   Response.Write "p"&objXML.ChildValInList(i,"title")&"/p" & vbCrLf
Next

Response.Write "hr /Test SingleNodehr /" & vbCrLf

objXML.SingleNode="/blogtech"
Response.Write "objXML.ChildVal(""description"")="& objXML.ChildVal("description") &"" & vbCrLf

Response.Write "hr /Test NodeValhr /" & vbCrLf
Response.Write "objXML.NodeVal(""/blogtech/description"")=" & objXML.NodeVal("/blogtech/description") & vbCrLf
Response.Write "hr /Test XpathNodesLength and NodeValInListhr /" & vbCrLf

N=objXML.XpathNodesLength("/blogtech/item/link")
Response.Write "pobjXML.XpathNodesLength(""/blogtech/item/link"")="&N&"/p"
For i=0 To N-1
   Response.Write "p"& objXML.NodeValInList("/blogtech/item/link",i) &"/p" & vbCrLf
Next

Set objXML = Nothing

%

(本文来源于图老师网站,更多请访问http://www.tulaoshi.com/webkaifa/)

来源:http://www.tulaoshi.com/n/20160219/1619837.html

延伸阅读
You Version Bible好不好   圣经是西方文化的重要源泉,它更是世界上发行量最大,发行时间最长,翻译成的语言最多,流行最广而读者面最广,影响最深远的一部书,因此被列入吉尼斯世界纪录。无论你是基督教徒与否,也无关你是无神论者与否,或许都可一读这本虽为宗教典籍,同时也可说是世界名著的。今天小编就为大家介绍一个可以让你了...
标签: Web开发
//香水坏坏 06-07-19 TKS:林子,给大家提供一个交流分享的地方 var Class = {   create: function() {     return function() {       this.initialize.apply(this, arguments);     }   ...
标签: 电脑入门
简介 System Volume Information文件夹是一个隐藏的系统文件夹,系统还原工具使用该文件夹来存储它的信息和还原点。您的计算机的每个分区上都有一个 System Volume Information 文件夹。System Volume Information文件夹,中文名称可以翻译为系统卷标信息。这个文件夹里就存储着系统还原的备份信息。 解决方法: 一、 右击我的电脑/...
class 文件是什么 1)、是对一个java类或一个java接口的全面描述; 2)、是对java程序二进制文件格式的精确定义; 3)、一个class文件中只能包含一个类或接口; 4)、作为程序传给jvm的中间语言; 5)、class文件不一定和java语言相关; class 文件内容 class文件包含了jvm所需知道的,关于类或接口的所有信息。 基本类型 ClassFile ...
标签: Web开发
按功能排列 NN:表明哪个早期Netscape版本支持这个标签 IE:表明哪个早期InternetExplorer版本支持这个标签 DTD:表明符合XHTML1.0DTD何级别的定义.S=Strict(严格),T=Transitional(过渡),andF=Frameset(框架) 开始标签用途(Purpose)NNIEDTD 基本标签 !DOCTYPE?文档类型(Definesth...

经验教程

428

收藏

65

精华推荐

ASP 类 Class入门

ASP 类 Class入门

cjb12202002

List Information About the Binary Files Used by an Application

List Information About the Binary Files Used by an Application

三亚小旋风

ASP 类 Class入门 推荐

ASP 类 Class入门 推荐

摸摸大撒

微博分享 QQ分享 QQ空间 手机页面 收藏网站 回到头部