读取xml某个节点的值
‘定义xml字符串内容地址
Dim xmlFileStr As String = ""
‘定义所需读取节点的名称
Dim readNodeName As String = ""
Function readXMl(ByVal xmlFileStr As String, ByVal readNodeName As String) As String
‘定义节点内容
Dim nodeValue As String = ""
Try
‘定义xml文档对象
Dim doc As New XmlDocument
‘加载xml内容
doc.LoadXml(xmlFileStr)
‘读取xml内容
Dim re As XmlNodeReader = New XmlNodeReader(doc)
Dim NodeName As String
‘循环查找节点
While re.Read
Select Case re.NodeType
Case XmlNodeType.Element
NodeName = re.Name
Case XmlNodeType.Text
If NodeName.Equals(readNodeName) Then
nodeValue = re.Value
End If
End Select
End While
Catch ex As Exception
MsgBox(ex.Message & vbCrLf & ex.StackTrace)
End Try
Return nodeValue
End Function
手机扫一扫
移动阅读更方便
你可能感兴趣的文章