好的,所以我在 vb 2010 中得到了很多帮助。如果你愿意的话,我需要你们提供更多的帮助。
我这里有一个 xml 文件
<?xml version="1.0" encoding="utf-8"?>
<!--XML Database.-->
<Data>
<Person>
<Name>hi</Name>
<Email>222</Email>
<Tel>2345</Tel>
</Person>
<Person>
<Name>hank</Name>
<Email>222</Email>
<Tel>2345</Tel>
</Person>
</Data>
我想将姓名、电子邮件和电话放入 3 个单独的数组中。我想我明白了。但是为什么现在不工作了。这里有什么问题。
Imports System.Xml
Imports System.IO
Public Class Form2
Dim array() As String
Dim testname As String
Dim namearray(1) As String
Dim emailarray(1) As String
Dim telarray(1) As String
Public Const path As String = "MyName.xml" 'it is in the bin folder.
Public Sub GetPerson()
Dim x As Integer = 0
Dim settings As New XmlReaderSettings
settings.IgnoreComments = True
settings.IgnoreWhitespace = True
Dim xmlIn As XmlReader = XmlReader.Create(path, settings)
If xmlIn.ReadToDescendant("Person") Then
Do
Dim person As New Person
xmlIn.ReadStartElement("Person")
namearray(x) = xmlIn("Name")
emailarray(x) = xmlIn("Email")
telarray(x) = xmlIn("Tel")
x = x + 1
Loop While xmlIn.ReadToNextSibling("Person")
End If
xmlIn.Close()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
GetPerson()
Search.Text = namearray(0)
End Sub
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
End Class