<?xml version="1.0" encoding="gb2312"?>2
<sys>3
<set>4
<ISPLAY intro="是否播放:Y否,N是">Y</ISPLAY>5
<filePath intro="文件路径">c:\adFile\</filePath>6
<date intro="日期">2007207</date>7
<version intro="版本号">01</version>8
</set>9
<t>TestValue</t>10
<tt>11
<ttt>12
<tttt>43</tttt>13
</ttt>14
</tt>15
</sys>
Imports System.Xml2

Public Class Form1Class Form13

4

Private Sub Form1_Load()Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load5
Me.TextBox1.Text = Me.GetNodeValue("ISPLAY")6
Me.TextBox2.Text = Me.GetNodeValue("tttt")7
Me.TextBox3.Text = Me.GetSysNodeValue("ISPLAY")8
End Sub9

10
'方法一11

Private Function GetNodeValue()Function GetNodeValue(ByVal node_name As String) 12
Dim xmlDoc1 As Xml.XmlDataDocument = New XmlDataDocument()13
xmlDoc1.Load("sys.xml")14
Dim node As XmlNode = xmlDoc1.SelectSingleNode("sys")15
Dim value_node As XmlNode = node.SelectSingleNode(".//" & node_name)16
If Not value_node Is Nothing Then '节点是否存在17
GetNodeValue = value_node.InnerText18
Else19
GetNodeValue = "error"20
End If21

22
End Function23

24
'方法二25

Public Function GetSysNodeValue()Function GetSysNodeValue(ByVal nodeName As String)26
Dim xmlDoc As New Xml.XmlDocument()27
xmlDoc.Load("sys.xml")28
Dim nodeList As Xml.XmlNodeList = xmlDoc.SelectSingleNode("sys").ChildNodes29
If Not nodeList.Item(0).Name Is Nothing Then '判断结点是否存在30
Return nodeList.Item(0).Item(nodeName).InnerText31
Else32
Return "error"33
End If34
End Function35

36
End Class37







