微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

VB读取xml处理类

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

原文地址:https://www.jb51.cc/vb/260594.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐