XML information class Version 1.0

515111299lei

515111299lei

2016-02-19 19:01

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

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

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

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

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

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

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

%

  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

%

展开更多 50%)
分享

猜你喜欢

XML information class Version 1.0

Web开发
XML information class Version 1.0

Display SQL Server Version Information

Web开发
Display SQL Server Version Information

s8lol主宰符文怎么配

英雄联盟 网络游戏
s8lol主宰符文怎么配

家庭双拼开背虾version 1.0的家常做法

电脑网络
家庭双拼开背虾version 1.0的家常做法

version

平面设计 标志设计 UI设计 VI设计
version

lol偷钱流符文搭配推荐

英雄联盟 网络游戏
lol偷钱流符文搭配推荐

XML 编程思想: UBL 1.0(以及 ebXML Core Components 等)

Web开发
XML 编程思想: UBL 1.0(以及 ebXML Core Components 等)

InstallShield Installation Information是什么

电脑入门
InstallShield Installation Information是什么

lolAD刺客新符文搭配推荐

英雄联盟
lolAD刺客新符文搭配推荐

XAML 实例演示之一

XAML 实例演示之一

全局XML Web服务体系结构新标准

全局XML Web服务体系结构新标准
下拉加载更多内容 ↓