技术开发 频道

Domino R5用Lotus Script处理XML

二、 VB原型

    新建一标准EXE工程,在Form1上加button : Command1;新建一标准Module(因为要用到Public Type):Module1。从菜单Project 导入Microsoft XML v3.0。

    (1)Module1中加入以下代码:

    Public Type XMLForDB

    AppName As String

    DB_UID As String

    DB_PWD As String

    DB_TNS As String

    End Type

    Public DBConfig() As XMLForDB

    Sub initConfig()

    Dim xml As DOMDocument

    Set xml = New DOMDocument

    xml.Load ("\Lotus\domino\DBConfig.xml ")                         //指定XML文件路径

    Dim root As IXMLDOMElement

    Set root = xml.documentElement

    Dim node As IXMLDOMNode

    Dim cNode As IXMLDOMNode

    Dim nodeList As IXMLDOMNodeList

    Set nodeList = root.getElementsByTagName("APPLICATION")

    ReDim DBConfig(nodeList.length)

    For i = 0 To nodeList.length - 1

    Set node = nodeList.Item(i)

    If (node.nodeType = 1 And node.hasChildNodes()) Then

    With DBConfig(i + 1)

    .AppName = UCase(node.Attributes.getNamedItem("name").Text)

    .DB_UID = node.selectSingleNode("USERID").Text

    .DB_PWD = node.selectSingleNode("PASSWORD").Text

    .DB_TNS = node.selectSingleNode("TNS").Text

    End With

    End If

    Next

    For i = 1 To UBound(DBConfig)

    With DBConfig(i)

    Debug.Print .AppName

    Debug.Print .DB_UID

    Debug.Print .DB_PWD

    Debug.Print .DB_TNS

    End With

    Next

    End Sub

    Function getDBConfig(name As String) As Variant

    Call initConfig

    getDBConfig = 0

    For i = 1 To UBound(DBConfig)

    If (UCase(DBConfig(i).AppName) = UCase(name)) Then

    getDBConfig = i

    Exit For

    End If

    Next

    End Function

    (2)在Command1一的Click中加入:

    Private Sub Command1_Click()

    Debug.Print "----------------- Test Start -------------------"

    If getDBConfig("app1") then

    Debug.Print "---------------- Test OK --------------------"

    Else

    Debug.Print "---------------- Test Error --------------------"

    End if

    End Sub

0
相关文章