vb.net读取xml文件中的节点内容

 
呵呵,先声明一下,会的就不用看了,本人的水平很菜,也就用xml文件配置一下软件中的一些参数.xml文件中的内容如下:
 

  15
  14


通过一个函数来读取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

每次只能读取一个值,效率不好,但总比没有的强,如果文件不存在或读取错误,则返回-1,所以判断返回值就行了.


你可能感兴趣的:(个性天空,vb.net,xml,string,exception,function,path)