读取XML文件的节点内的内容

时间:2023-03-09 05:49:41
读取XML文件的节点内的内容
<?xml version="1.0" encoding="utf-8" ?>
<data>
<tag3>15</tag3>
<tag6>14</tag6>
</data>
Private Function GetXML(ByVal name As String) As String
Dim path As String
Dim xx As String = ""
path = Application.StartupPath + "\xbd.xml" '文件的地址,相对位置
Try
Dim reader As New Xml.XmlTextReader(path)
reader.ReadToFollowing(name) '读取到文件指定的节点处,如tag3
xx = reader.ReadString '读取里面的值
reader.Close()
Catch ex As Exception
xx = -1
End Try
Return xx
End Function