///////////////////////////////////////////////////////////////////////////////////////////////////////
' Author : ivy8890
' Created : 2005/04/15
' Purpose : Get xml file and parse it and keep all APPLICATION content to DBConfig arrary.
' History : <<< ID : 999 Type[Add, Update, Del] Start yyyy/mm/dd Department Purpose >>>
' XXXXXXXXXXXXXXXXXXXXXXXXXXXX
' <<< ID : 999 Type[Add, Update, Del] End yyyy/mm/dd Department>>>
' ///////////////////////////////////////////////////////////////////////////////////////////////////////
Sub initConfig()
On Error GoTo bottom
Dim xml
Set xml = CreateObject("Msxml2.DOMDocument")
xml.Load (XMLPATH)
Dim root
Set root = xml.documentElement
Dim node
Dim nodeList
Set nodeList = root.getElementsByTagName("APPLICATION")
Dim AppName As String
Dim uid As String
Dim pwd As String
Dim TNS As String
Redim DBConfig(nodeList.length)
For i = 1 To nodeList.length
Set node = nodeList.Item(i-1)
If (node.nodeType = 1 And node.hasChildNodes()) Then
DBConfig(i).AppName = Ucase(node.Attributes.getNamedItem("name").Text)
DBConfig(i).DB_UID = node.selectSingleNode("USERID").Text
DBConfig(i).DB_PWD = node.selectSingleNode("PASSWORD").Text
DBConfig(i ).DB_TNS = node.selectSingleNode("TNS").Text
End If
Next
bottom:
Exit Sub
End Sub
' ///////////////////////////////////////////////////////////////////////////////////////////////////////
' Author : ivy8890
' Created : 2005/04/15
' Purpose : Get specified application config information.
' Return : (1) >0 index of DBConfig
' (2) err : 0
' History : <<< ID : 999 Type[Add, Update, Del] Start yyyy/mm/dd Department Purpose >>>
' XXXXXXXXXXXXXXXXXXXXXXXXXXXX
' <<< ID : 999 Type[Add, Update, Del] End yyyy/mm/dd Department>>>
' ///////////////////////////////////////////////////////////////////////////////////////////////////////
Function getDBConfig(sname As String) As Integer
getDBConfig = 0
DB_Result = 0
On Error GoTo bottom
Call initConfig
For i = 1 To Ubound(DBConfig)
If (Ucase(DBConfig(i).AppName) = Ucase(sname)) Then
getDBConfig = i
DB_Result = i
DB_UID = DBConfig(i).DB_UID
DB_PWD = DBConfig(i).DB_PWD
DB_TNS = DBConfig(i).DB_TNS
Exit For
End If
Next
bottom:
Exit Function
End Function
四、 配置和使用
为了使多个应用使用,将以上代码保存为DBConfig.lss。*.Lss文件位置 : Server端 Lotus\domino目录下;Client端 Lotus\notes目录下。
(1)导入Lss文件
如果DBConfig.lss放在Lotus\notes目录下,使用时要用Include语句,%Include “DBConfig.lss”; 如果放在Lotus\notes\lss目录下,要用%Include “lss/DBConfig.lss”。