大橙子网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
这篇文章主要介绍“VB.NET怎么读取XML文件”,在日常操作中,相信很多人在VB.NET怎么读取XML文件问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”VB.NET怎么读取XML文件”的疑惑有所帮助!接下来,请跟着小编一起来学习吧!
在龙海等地区,都构建了全面的区域性战略布局,加强发展的系统性、市场前瞻性、产品创新能力,以专注、极致的服务理念,为客户提供成都做网站、成都网站设计 网站设计制作按需策划,公司网站建设,企业网站建设,高端网站设计,网络营销推广,外贸网站制作,龙海网站建设费用合理。
VB.NET未开发人员带来了不一样的开发方式。其中特有的各种特点和语言特性为编程人员开发程序提供了很大的帮助。我们今天就来看一段实现VB.NET读取XML文件的VB代码。使用了递归方式。
VB.NET Socket编程实际操作方法介绍
迅速掌握VB.NET读取INI文件操作方法
VB.NET Hashtable用法相关概念详解
VB.NET键盘事件相关内容概览
VB.NET正则表达式应用经验分享
VB.NET读取XML文件代码如下:
Imports System.xml
Public Class Form1Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows 窗体设计器生成的代码 "
Public Sub New()Sub New()
MyBase.New()
'该调用是 Windows 窗体设计器所必需的。
InitializeComponent()
'在 InitializeComponent()
调用之后添加任何初始化
End Sub
'窗体重写 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 窗体设计器所必需的
Private components As System.
ComponentModel.IContainer'注意: 以下过程是 Windows 窗体设计
器所必需的'可以使用 Windows 窗体设计器修改此过程。
'不要使用代码编辑器修改它。
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 & "节点找到")
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("此节点有属性:")
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
("此节点有子节点:" & vbCrLf)Dim child As XmlNode
For Each child In node.ChildNodes
enumeratenode(child, indentval + 1)
Next
End If
End Sub
End Class
到此,关于“VB.NET怎么读取XML文件”的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注创新互联网站,小编会继续努力为大家带来更多实用的文章!