⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 class1.cls

📁 多种数据库或数据文件转化成工行网上银行文件格式
💻 CLS
字号:
VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "Class1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Option Explicit

 

Private document As DOMDocument

Private action As IXMLDOMElement

 

Public Property Let xml(ByVal xml As String)

    Set document = New DOMDocument

    document.loadXML xml

    'document.Load App.Path + "\from.xml"

    Set action = document.selectSingleNode("action")

End Property

 

Function getNodeAttribute(ByVal attribute_name As String)

    Dim element As IXMLDOMElement

    Set element = action

    If element Is Nothing Then

        getNodeAttribute = ""

    Else

        getNodeAttribute = element.getAttribute(attribute_name)

    End If

End Function

 

Function getNodeValue(ByVal node_name As String)

    Dim node As IXMLDOMNode

    Set node = action.selectSingleNode(node_name)

    If node Is Nothing Then

        getNodeValue = ""

    Else

        getNodeValue = node.Text

    End If

End Function

 

Public Sub createDocument(ByVal name As String)

    Set document = New DOMDocument

    Set action = document.createElement("action")

    action.setAttribute "name", name

    document.appendChild action

End Sub

 

Public Sub appendNode(ByVal node_name As String, ByVal node_value As String)

    Dim node As IXMLDOMNode

    Set node = action.ownerDocument.createElement(node_name)

    node.Text = node_value

    action.appendChild node

End Sub

 

Public Property Get xml() As String

    xml = document.xml

    'document.save App.Path + "\to.xml"

End Property

 

调用程序如下:

Option Explicit

 

Private Sub Form_Load()

    Dim obj As New ClsXml

    obj.xml = "<action name=""login""><username>a</username><password>1</password></action>"

    MsgBox obj.getNodeAttribute("name")

    MsgBox obj.getNodeValue("username")

    MsgBox obj.getNodeValue("password")

    obj.createDocument "logout"

    obj.appendNode "username", "a"

    obj.appendNode "password", "1"

    MsgBox obj.xml

    Unload Me

End Sub


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -