XML Show
1
<?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>
<?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> 1
Imports System.Xml
2
Public Class Form1
3
4
Private 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(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(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
36
End Class
37
Imports System.Xml2
Public Class Form13

4
Private 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(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(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


浙公网安备 33010602011771号