這篇文章主要介紹“VB.NET怎么讀取XML文件”,在日常操作中,相信很多人在VB.NET怎么讀取XML文件問(wèn)題上存在疑惑,小編查閱了各式資料,整理出簡(jiǎn)單好用的操作方法,希望對(duì)大家解答”VB.NET怎么讀取XML文件”的疑惑有所幫助!接下來(lái),請(qǐng)跟著小編一起來(lái)學(xué)習(xí)吧!
在龍海等地區(qū),都構(gòu)建了全面的區(qū)域性戰(zhàn)略布局,加強(qiáng)發(fā)展的系統(tǒng)性、市場(chǎng)前瞻性、產(chǎn)品創(chuàng)新能力,以專注、極致的服務(wù)理念,為客戶提供成都做網(wǎng)站、成都網(wǎng)站設(shè)計(jì) 網(wǎng)站設(shè)計(jì)制作按需策劃,公司網(wǎng)站建設(shè),企業(yè)網(wǎng)站建設(shè),高端網(wǎng)站設(shè)計(jì),網(wǎng)絡(luò)營(yíng)銷推廣,外貿(mào)網(wǎng)站制作,龍海網(wǎng)站建設(shè)費(fèi)用合理。
VB.NET未開(kāi)發(fā)人員帶來(lái)了不一樣的開(kāi)發(fā)方式。其中特有的各種特點(diǎn)和語(yǔ)言特性為編程人員開(kāi)發(fā)程序提供了很大的幫助。我們今天就來(lái)看一段實(shí)現(xiàn)VB.NET讀取XML文件的VB代碼。使用了遞歸方式。
VB.NET Socket編程實(shí)際操作方法介紹
迅速掌握VB.NET讀取INI文件操作方法
VB.NET Hashtable用法相關(guān)概念詳解
VB.NET鍵盤事件相關(guān)內(nèi)容概覽
VB.NET正則表達(dá)式應(yīng)用經(jīng)驗(yàn)分享
VB.NET讀取XML文件代碼如下:
Imports System.xml
Public Class Form1Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows 窗體設(shè)計(jì)器生成的代碼 "
Public Sub New()Sub New()
MyBase.New()
'該調(diào)用是 Windows 窗體設(shè)計(jì)器所必需的。
InitializeComponent()
'在 InitializeComponent()
調(diào)用之后添加任何初始化
End Sub
'窗體重寫(xiě) dispose 以清理組件列表。
Protected Overloads Overrides
Sub Dispose()Sub Dispose(ByVal
disposing As Boolean)If disposing Then
If Not (components Is Nothing)
Thencomponents.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Windows 窗體設(shè)計(jì)器所必需的
Private components As System.
ComponentModel.IContainer'注意: 以下過(guò)程是 Windows 窗體設(shè)計(jì)
器所必需的'可以使用 Windows 窗體設(shè)計(jì)器修改此過(guò)程。
'不要使用代碼編輯器修改它。
Friend WithEvents input As System.
Windows.Forms.TextBoxFriend WithEvents outtext As System.
Windows.Forms.TextBoxFriend WithEvents Button1 As System.
Windows.Forms.Button
Private Sub InitializeComponent()
Sub InitializeComponent()Me.input = New System.Windows.
Forms.TextBoxMe.outtext = New System.Windows.
Forms.TextBoxMe.Button1 = New System.Windows.
Forms.ButtonMe.SuspendLayout()
'
'input
'
Me.input.Location = New System.
Drawing.Point(16, 8)Me.input.Name = "input"
Me.input.Size = New System.
Drawing.Size(464, 21)Me.input.TabIndex = 0
Me.input.Text = "http://127.0.0.1/
fileup/people.xml"'
'outtext
'
Me.outtext.BackColor = System.
Drawing.SystemColors.HighlightTextMe.outtext.BorderStyle = System.
Windows.Forms.BorderStyle.FixedSingleMe.outtext.Location = New
System.Drawing.Point(0, 40)Me.outtext.Multiline = True
Me.outtext.Name = "outtext"
Me.outtext.ReadOnly = True
Me.outtext.ScrollBars = System.
Windows.Forms.ScrollBars.BothMe.outtext.Size = New System.
Drawing.Size(624, 472)Me.outtext.TabIndex = 1
Me.outtext.Text = "TextBox2"
'
'Button1
'
Me.Button1.Location = New
System.Drawing.Point(504, 8)Me.Button1.Name = "Button1"
Me.Button1.Size = New System.
Drawing.Size(96, 24)Me.Button1.TabIndex = 2
Me.Button1.Text = "讀 取"
'
'Form1
'
Me.AutoScaleBaseSize = New
System.Drawing.Size(6, 14)Me.ClientSize = New System.
Drawing.Size(632, 517)Me.Controls.Add(Me.Button1)
Me.Controls.Add(Me.outtext)
Me.Controls.Add(Me.input)
Me.Name = "Form1"
Me.Text = "Form1"
Me.ResumeLayout(False)
End Sub
#End Region
Private Sub Button1_Click()
Sub Button1_Click(ByVal sender
As System.Object, ByVal e As
System.EventArgs) Handles
Button1.ClickDim doc As xmldocument =
New xmldocumentDim y As String
doc.Load(input.Text)
Dim rootnode As XmlElement =
doc.DocumentElementouttext.Text = ""
enumeratenode(rootnode, 0)
End Su
Private Sub enumeratenode()
Sub enumeratenode(ByVal node
As XmlNode, ByVal indentval
As Integer)Dim type As String
Select Case node.NodeType
Case XmlNodeType.Element
type = "元素"
Case XmlNodeType.Text
type = "文本"
Case XmlNodeType.Comment
type = "注釋"
Case Else
outtext.AppendText(".")
End Select
outtext.AppendText(type & "節(jié)點(diǎn)找到")
Select Case node.NodeType
Case XmlNodeType.Element
outtext.AppendText(",name="
& node.Name & vbCrLf)Case XmlNodeType.Text
outtext.AppendText(",content="
& node.Value & vbCrLf)Case XmlNodeType.Comment
outtext.AppendText(",content="
& node.Value & vbCrLf)Case Else
outtext.AppendText(".")
End Select
If Not node.Attributes Is Nothing Then
If node.Attributes.Count <> 0 Then
outtext.AppendText("此節(jié)點(diǎn)有屬性:")
Dim attr As XmlAttribute
For Each attr In node.Attributes
outtext.AppendText(attr.Name
& " =" & attr.Value & vbCrLf)Next
End If
End If
If node.HasChildNodes Then
outtext.AppendText
("此節(jié)點(diǎn)有子節(jié)點(diǎn):" & vbCrLf)Dim child As XmlNode
For Each child In node.ChildNodes
enumeratenode(child, indentval + 1)
Next
End If
End Sub
End Class
到此,關(guān)于“VB.NET怎么讀取XML文件”的學(xué)習(xí)就結(jié)束了,希望能夠解決大家的疑惑。理論與實(shí)踐的搭配能更好的幫助大家學(xué)習(xí),快去試試吧!若想繼續(xù)學(xué)習(xí)更多相關(guān)知識(shí),請(qǐng)繼續(xù)關(guān)注創(chuàng)新互聯(lián)網(wǎng)站,小編會(huì)繼續(xù)努力為大家?guī)?lái)更多實(shí)用的文章!