Option Explicit
Option Compare Text
DefInt I
DefStr S
DefDate D
DefLng L
DefBool B
Dim mvarsXmlFile As String 'xmlFile属性内存变量
Dim mvarsXmlContent As String 'xmlContent属性内存变量
Dim mvarsXmlRoot As MSXML2.DOMDocument 'xmlRoot属性内存变量
Public Property Let XmlRoot(ByRef vData As MSXML2.DOMDocument)
Set mvarsXmlRoot = vData
End Property
Public Property Get XmlRoot() As MSXML2.DOMDocument
Set XmlRoot = mvarsXmlRoot
End Property
Public Property Let XmlFile(ByVal vData As String)
mvarsXmlFile = vData
End Property
Public Property Get XmlFile() As String
XmlFile = mvarsXmlFile
End Property
Public Property Let XmlContent(ByVal vData As String)
mvarsXmlContent = vData
End Property
Public Property Get XmlContent() As String
XmlContent = mvarsXmlContent
End Property
'类初始化
Private Sub Class_Initialize()
Me.XmlContent = ""
Me.XmlFile = ""
'Me.XmlRoot = New MSXML2.DOMDocument
Set mvarsXmlRoot = New MSXML2.DOMDocument
End Sub
'Private Sub Class_Terminate()
' XmlRoot.abort
'
'End Sub
Function fun_XmlLoad(ByVal sFilePath As String) As Boolean
On Error GoTo Morn
fun_XmlLoad = False
If Dir(sFilePath, vbNormal) = "" Then Exit Function
Me.XmlRoot.Load sFilePath
Me.XmlFile = Trim(sFilePath)
Do While XmlRoot.readyState <> 4
DoEvents
Loop
Me.XmlFile = XmlRoot.XML
fun_XmlLoad = True
Exit Function
Morn:
End Function
'找到节点对象
Function fun_GetElement(ByVal sItem As String) As MSXML2.IXMLDOMElement
'Set fun_GetElement = New ms
On Error GoTo Morn
Set fun_GetElement = Me.XmlRoot.selectSingleNode(sItem)
Exit Function
Morn:
End Function
'读取节点text函数
Function fun_GetElementText(ByVal sItem As String) As String
Dim oElement As MSXML2.IXMLDOMElement
fun_GetElementText = ""
On Error GoTo Morn
Set oElement = Me.XmlRoot.selectSingleNode(sItem)
If oElement Is Nothing Then Exit Function
fun_GetElementText = oElement.Text
Exit Function
Morn:
End Function
'读取节点属性值函数,默认读取value属性值
Function fun_GetProperty(ByVal sItem As String, Optional ByVal sPropertyName = "value") As String
Dim oElement As MSXML2.IXMLDOMElement
fun_GetProperty = ""
On Error GoTo Morn
Set oElement = Me.XmlRoot.selectSingleNode(sItem)
Set oElement = Me.XmlRoot.selectSingleNode(sItem)
If oElement Is Nothing Then Exit Function
fun_GetProperty = oElement.getAttribute(sPropertyName)
Exit Function
Morn:
End Function
VB读取xml处理类
精选 转载
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
MybatisPlus基础Xml使用教程
MybatisPlus基础最全教程,里面包含操作的核心教程以及重点难点,很适合新手以及中高级开发学习
mybatis mybatisplus springboot -
VB操作xml的简单例子
李国帅2006-3-23 13:16有些东西用起
xml xml文件 -
vb 创建xml
引用:://hi.baidu.com/xoyowozo/blog/item/7544d9a8c0397ebdca130c7c.html1 打开VB6.0 File--->New Project---->Standard ExE---->OK2 打开菜单Project---->Reference---->选中Microsoft XML,V6.0---->OK3 打开菜单Project---->Components---->选中Microsoft Windows Common Controls 6.0---->确定,4 新建如下的For
程序语言--------VB xml xml文件 microsoft 打开菜单 -
VB操作XML详细用法xml 数据 相对路径 子节点 数据类型