2020年7月6日 星期一

vb.net 取得XML的資料 [Get XML Information]


1
2
Imports System
Imports System.Xml


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<imgdir name="0100000.img">
 <imgdir name="info">
  <string name="link" value="0100100"/>
  <int name="level" value="1"/>
  <int name="bodyAttack" value="1"/>
  <int name="maxHP" value="15"/>
  <int name="speed" value="-65"/>
  <int name="PADamage" value="2"/>
  <int name="PDRate" value="10"/>
  <int name="MADamage" value="1"/>
  <int name="MDRate" value="10"/>
  <int name="acc" value="10"/>
  <int name="pushed" value="5"/>
  <float name="fs" value="10.0"/>
  <int name="exp" value="3"/>
  <int name="summonType" value="1"/>
  <int name="category" value="1"/>
  <string name="mobType" value="1N"/>
 </imgdir>
</imgdir>








 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim XmlDoc As XmlDocument = New XmlDocument

        XmlDoc.Load(Application.StartupPath & "\0100000.img.xml")

        Dim blnAdd As Boolean = False

        TextBox1.Text = "等級 = 0"
        TextBox2.Text = "血量 = 0"
        TextBox3.Text = "魔量 = 0"
        TextBox4.Text = "速度 = 0"
        TextBox5.Text = "物攻 = 0"
        TextBox6.Text = "物防 = 0"
        TextBox7.Text = "魔攻 = 0"
        TextBox8.Text = "魔防 = 0"
        TextBox9.Text = "經驗 = 0"

        For Each Element As XmlElement In XmlDoc.SelectNodes("//*")

            If Element.Name = "imgdir" Then
                If Element.Attributes("name").Value = "info" Then
                    blnAdd = True
                Else
                    blnAdd = False
                End If
            ElseIf blnAdd = True Then
                'For Each Attribute As XmlAttribute In Element.Attributes
                'ListBox1.Items.Add(Attribute.Name & " = " & Attribute.Value)
                'Next

                Select Case Element.Attributes("name").Value
                    Case "level"
                        TextBox1.Text = "等級 = " & Element.Attributes("value").Value
                    Case "maxHP"
                        TextBox2.Text = "血量 = " & Element.Attributes("value").Value
                    Case "maxMP"
                        TextBox3.Text = "魔量 = " & Element.Attributes("value").Value
                    Case "speed"
                        TextBox4.Text = "速度 = " & Element.Attributes("value").Value
                    Case "PADamage"
                        TextBox5.Text = "物攻 = " & Element.Attributes("value").Value
                    Case "PDDamage"
                        TextBox6.Text = "物防 = " & Element.Attributes("value").Value
                    Case "MADamage"
                        TextBox7.Text = "魔攻 = " & Element.Attributes("value").Value
                    Case "MDDamage"
                        TextBox8.Text = "魔防 = " & Element.Attributes("value").Value
                    Case "exp"
                        TextBox9.Text = "經驗 = " & Element.Attributes("value").Value
                End Select

                'ListBox1.Items.Add(Element.Attributes("name").Value & " = " & Element.Attributes("value").Value)
            End If


        Next
    End Sub
End Class


沒有留言:

張貼留言