Add a registry "Class implementation" to the website

zhaozj2021-02-16  95

<% '----------------------------------------------- ------------------------------------- 'class name: RegistryObject page information in the registry category' author: Zhang Shaoyu (Tonton) 'Mailbox: Tonton@yeah.net' Time: August 1st, 2004 Description: Imitate the way to register in Windows, combine XML and ASP technology to add a dedicated "Registry" class to the website. 'URL: http://blog.9cbs.net/tonton/archive/2004/08/01/58198.aspx' copyright: Reader can use this program for any use, if you want to publish, reprint, please keep the above copyright information ! '------------------------------------- -----------------------------------

Const node_element = 1const Node_Text = 3

Class RegistryObject Private mDom Public Path 'registry path Public Encoding' registry encoding Public DefaultValue 'when reading the key, the default value Private Sub Class_Initialize returned key does not exist if the sub () DefaultValue = Empty Encoding = "gb2312" Set mDom = Nothing End Sub Private Sub Class_Terminate () Set mDom = Nothing End Sub Public Function NewDom () Set NewDom = Server.CreateObject ( "Microsoft.XMLDOM") End Function Private Property Get Dom () Dim Nde If mDom Is Nothing Then Set mDom = NewDom () mDom.async = False mDom.Load Path If mDom.parseError.errorCode = & H800C0006 Then 'file not found Initial ElseIf mDom.parseError <> 0 Then Exit Property End If End If Set Dom = mDom End Property Public Function Initial () DIM NDE SET MDOM = newdom () with mdom set nde = .creat EPROCESSINGINSTRUCTION ("XML", "Version = '1.0' Encoding = '" & Encoding & "'") .Appendchild (nde) set nde = .createElement ("registry") .appendchild (nde) end with mdom.save path end Function Public Function CreateChannel (CHANNEL) with dom set createchannel = .selectsinglenode ("//" & channel) if createchannel is nothing the set createchannel = .createnode (node_element, channel, ""

) .DocumentElement.appendChild (CreateChannel) .Save Path End If End With End Function Public Function GetAllChannels () Dim Result Dim Nde, i With Dom With .documentElement.childNodes If .length = 0 Then Result = Split ( "", 0) Else Redim Result (.length - 1) for i = 0 to .length - 1 Result (i) = .Ind (i) .NodeName Next End Id with end with getAllChannels = Result End Function PUBLIC FUNCTION Deletechannel (Channel) DIM Selection With Dom Set Selection = .selectNodes ( "//" & Channel) Selection.RemoveAll .Save Path End With End Function Public Function CreateSection (Channel, Section) Dim Nde With Dom Set Nde = .selectSingleNode ( "//" & Cha Nnel & "/" & section) if nde is nothing the set nde = .selectsinglenode ("//" & channel) if nde is nothing the set nde = .createnode (node_element, channel, "") .documentelement.Appendchild (NDE ) End if set createsection = .createnode (node_element, section, ""

) Nde.appendChild (CreateSection) .Save Path End If End With End Function Public Function GetAllSections (Channel) Dim Result Dim Nde, i With Dom Set Nde = .selectSingleNode ( "//" & Channel) If Not Nde Is Nothing Then With Nde.childnodes if .length = 0 Then Result = split ("", 0) else redim results (.length - 1) for i = 0 to .length - 1 results (i) = .ITEM (i) .NodeName Next End If end with else result = split ("", 0) end if End with getallsections = result end function public function clearllsections (channel) DIM selection with dom set selection = .selectnodes ("//" & channel) SELEC tion.RemoveAll .Save Path End With End Function Public Function DeleteSection (Channel, Section) Dim Selection With Dom Set Selection = .selectNodes ( "//" & Channel & "/" & Section) Selection.RemoveAll .Save Path End With End Function Public Function GetAllKeys (Channel, Section) Dim Result Dim Nde, I with Dom Set Nde = .selectsinglenode ("//" & Channel & "/" & section) if not nde is nothing kiln nde.childnodes if .length = 0 Then Result = split ("" "

0) Else Redim Result (.length - 1) for i = 0 to .length - 1 results (i) = .Ind (i) .nodeename next end if end with else result = split (", 0) end if End With GetAllKeys = Result End Function Public Sub SaveValue (Channel, Section, Key, Value) Dim Nde, Nde2, ItemNode With Dom Set ItemNode = .selectSingleNode ( "//" & Channel & "/" & Section & "/" & Key) If ItemNode Is Nothing Then Set Nde = .selectSingleNode ( "//" & Channel) If Nde Is Nothing Then Set Nde = .createNode (NODE_ELEMENT, Channel, "") .documentElement.appendChild (Nde) End If Set Nde2 = Nde.selectsinglenode ("//" & section) if nde2 is nothing the set nde2 = .createnode (node_element, section, ") NDE.APPENDCHILD (NDE2) endiff set ItemNode = .createNode (NODE_ELEMENT, Key, "") Nde2.appendChild (ItemNode) End If ItemNode.Text = Value .Save Path End With End Sub Public Function ReadValue (Channel, Section, Key) Dim Nde With Dom Set Nde =. Selectsinglenode ("//" & channel & "/" & section & "/" & key) if nde is nothing the readvalue = defaultValue else readvalue =

Nde.Text End If EndallVale (Channel, Section) Dim Result Dim Nde, I with Dom Set Nde = .selectsinglenode ("//" & Channel & "/" & section) if not nde is nothing then With nde.childnodes if .length = 0 Then Result = split ("", 0) Else Redim Result (.length - 1) for i = 0 to .length - 1 set results (i) = new registryKey Result (i). Name = .item (i) .NodeName Result (i) .value = .Item (i) .text next end if endew with else result = split ("", 0) end if End with getAllValues ​​= Result End Functionend ClassClass RegistryKey Public Name Public ValueEnd Class%>

转载请注明原文地址:https://www.9cbs.com/read-11285.html

New Post(0)