2<sys>
3 <set>
4 <ISPLAY intro="是否播放:Y否,N是">YISPLAY>
5 <filePath intro="文件路径">c:adFilefilePath>
6 <date intro="日期">2007207date>
7 <version intro="版本号">01version>
8 set>
9 <t>TestValuet>
10 <tt>
11 <ttt>
12 <tttt>43tttt>
13 ttt>
14 tt>
15sys>
2Public Class Form1Class Form1
3
4 Private Sub Form1_Load()Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
5 Me.TextBox1.Text = Me.GetNodeValue("ISPLAY")
6 Me.TextBox2.Text = Me.GetNodeValue("tttt")
7 Me.TextBox3.Text = Me.GetSysNodeValue("ISPLAY")
8 End Sub
9
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.InnerText
18 Else
19 GetNodeValue = "error"
20 End If
21
22 End Function
23
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").ChildNodes
29 If Not nodeList.Item(0).Name Is Nothing Then '判断结点是否存在
30 Return nodeList.Item(0).Item(nodeName).InnerText
31 Else
32 Return "error"
33 End If
34 End Function
35
36End Class
37