http://hanhead.tistory.com/entry/readwrite-configuration-class-xml-version

<%
'Option Explicit

Class configs

Private mClassName
Private mConfigRootPath
Private mItems
Private mXmlRootNodeName
Private mConfigName

Private Sub Class_Initialize()
 mClassName = "configs class"
 mXmlRootNodeName = "configs"
 mConfigRootPath = server.mappath("./")
End Sub

Public Sub Load(configname)
 Dim xdom
 Dim i
 
 mConfigName = configname
 Set mItems = Server.CreateObject("scripting.dictionary")
 Set xdom = server.CreateObject("microsoft.xmldom")
 xdom.load mconfigrootpath & "\" & configname & ".xml"
 If xdom.parseerror.errorcode <> 0 Then
  Err.raise vbObjectError, mClassName, xdom.parseerror.reason
 Else
  if xdom.documentelement.nodename = mXmlRootNodeName Then
   For i=0 To xdom.documentelement.childnodes.length-1
    mItems.add xdom.documentelement.childnodes(i).nodename, xdom.documentelement.childnodes(i).text
   Next
  Else
   Err.raise vbObjectError, mClassName, "Invalid Configuration File"
  End If
 End If
 Set xdom = nothing
End Sub

Public Sub Save()
 Dim xdom
 Dim i

 Set xdom = server.CreateObject("microsoft.xmldom")
 xdom.load mconfigrootpath & "\" & mConfigName & ".xml"
 If xdom.parseerror.errorcode <> 0 Then
  Err.raise vbObjectError, mClassName, xdom.parseerror.reason
 Else
  if xdom.documentelement.nodename = mXmlRootNodeName Then
   For i= xdom.documentelement.childnodes.length-1 To 0 Step -1
    xdom.documentelement.removechild(xdom.documentelement.childnodes(i))
   Next
   Dim keys, items, newelement
   keys = mItems.keys()
   items = mItems.items()
   For i=0 To mItems.count-1
    Set newelement = xdom.createElement(keys(i))
    newelement.text = items(i)
    xdom.documentelement.appendchild newelement
    Set newelement = Nothing
   Next
   xdom.save mconfigrootpath & "\" & mConfigName & ".xml"
  Else
   Err.raise vbObjectError, mClassName, "Invalid Configuration File"
  End If
 End If
 Set xdom = nothing
 Set mItems = Nothing
End Sub

Public Sub Add(key, value)
 mItems.Add key, value
End Sub

Public Function Item(key)
 Item = mItems.Item(key)
End Function

End Class

'example.asp
'
'Dim a
'Set a = new configs
'a.load "example"
'response.write a.item("test1")
'a.add "test4", "33>3"
'a.save
'Set a = nothing

'example.xml
'
'<configs><test1>1111</test1><test2>2222</test2><test3>3333</test3></configs>
%>

'asp' 카테고리의 다른 글

dbhelper class  (0) 2010.08.24
FSO example  (0) 2010.08.24
Encryption Utils Class  (0) 2010.08.24
엑셀(CSV) 파일 DB에 입력하기  (2) 2010.07.09
asp로 화일업로드 형태를 취해 csv아니면 excel화일을 ms-sql db로 저장하기  (0) 2010.07.09

+ Recent posts