VB.NET怎么讀取XML文件

這篇文章主要介紹“VB.NET怎么讀取XML文件”,在日常操作中,相信很多人在VB.NET怎么讀取XML文件問題上存在疑惑,小編查閱了各式資料,整理出簡單好用的操作方法,希望對大家解答”VB.NET怎么讀取XML文件”的疑惑有所幫助!接下來,請跟著小編一起來學習吧!

在龍海等地區(qū),都構(gòu)建了全面的區(qū)域性戰(zhàn)略布局,加強發(fā)展的系統(tǒng)性、市場前瞻性、產(chǎn)品創(chuàng)新能力,以專注、極致的服務理念,為客戶提供成都做網(wǎng)站、成都網(wǎng)站設(shè)計 網(wǎng)站設(shè)計制作按需策劃,公司網(wǎng)站建設(shè),企業(yè)網(wǎng)站建設(shè),高端網(wǎng)站設(shè)計,網(wǎng)絡營銷推廣,外貿(mào)網(wǎng)站制作,龍海網(wǎng)站建設(shè)費用合理。

VB.NET未開發(fā)人員帶來了不一樣的開發(fā)方式。其中特有的各種特點和語言特性為編程人員開發(fā)程序提供了很大的幫助。我們今天就來看一段實現(xiàn)VB.NET讀取XML文件的VB代碼。使用了遞歸方式。

  • VB.NET Socket編程實際操作方法介紹

  • 迅速掌握VB.NET讀取INI文件操作方法

  • VB.NET Hashtable用法相關(guān)概念詳解

  • VB.NET鍵盤事件相關(guān)內(nèi)容概覽

  • VB.NET正則表達式應用經(jīng)驗分享

VB.NET讀取XML文件代碼如下:

  1. Imports System.xml  

  2. Public Class Form1Class Form1  

  3. Inherits System.Windows.Forms.Form  

  4. #Region " Windows 窗體設(shè)計器生成的代碼 "  

  5. Public Sub New()Sub New()  

  6. MyBase.New()  

  7. '該調(diào)用是 Windows 窗體設(shè)計器所必需的。  

  8. InitializeComponent()  

  9. '在 InitializeComponent() 
    調(diào)用之后添加任何初始化  

  10. End Sub 

  1. '窗體重寫 dispose 以清理組件列表。  

  2. Protected Overloads Overrides 
    Sub Dispose()Sub Dispose(ByVal 
    disposing As Boolean)  

  3. If disposing Then  

  4. If Not (components Is Nothing) 
    Then  

  5. components.Dispose()  

  6. End If  

  7. End If  

  8. MyBase.Dispose(disposing)  

  9. End Sub 

  1. 'Windows 窗體設(shè)計器所必需的  

  2. Private components As System.
    ComponentModel.IContainer  

  3. '注意: 以下過程是 Windows 窗體設(shè)計
    器所必需的  

  4. '可以使用 Windows 窗體設(shè)計器修改此過程。  

  5. '不要使用代碼編輯器修改它。  

  6. Friend WithEvents input As System.
    Windows.Forms.TextBox  

  7. Friend WithEvents outtext As System.
    Windows.Forms.TextBox  

  8. Friend WithEvents Button1 As System.
    Windows.Forms.Button  

  9. <System.Diagnostics.DebuggerStepThrough()> 
    Private Sub InitializeComponent()
    Sub InitializeComponent()  

  10. Me.input = New System.Windows.
    Forms.TextBox  

  11. Me.outtext = New System.Windows.
    Forms.TextBox  

  12. Me.Button1 = New System.Windows.
    Forms.Button  

  13. Me.SuspendLayout()  

  14. '  

  15. 'input  

  16. '  

  17. Me.input.Location = New System.
    Drawing.Point(16, 8)  

  18. Me.input.Name = "input" 

  19. Me.input.Size = New System.
    Drawing.Size(464, 21)  

  20. Me.input.TabIndex = 0 

  21. Me.input.Text = "http://127.0.0.1/
    fileup/people.xml" 

  22. '  

  23. 'outtext  

  24. '  

  25. Me.outtext.BackColor = System.
    Drawing.SystemColors.HighlightText  

  26. Me.outtext.BorderStyle = System.
    Windows.Forms.BorderStyle.FixedSingle  

  27. Me.outtext.Location = New 
    System.Drawing.Point(0, 40)  

  28. Me.outtext.Multiline = True 

  29. Me.outtext.Name = "outtext" 

  30. Me.outtext.ReadOnly = True 

  31. Me.outtext.ScrollBars = System.
    Windows.Forms.ScrollBars.Both  

  32. Me.outtext.Size = New System.
    Drawing.Size(624, 472)  

  33. Me.outtext.TabIndex = 1 

  34. Me.outtext.Text = "TextBox2" 

  35. '  

  36. 'Button1  

  37. '  

  38. Me.Button1.Location = New 
    System.Drawing.Point(504, 8)  

  39. Me.Button1.Name = "Button1" 

  40. Me.Button1.Size = New System.
    Drawing.Size(96, 24)  

  41. Me.Button1.TabIndex = 2 

  42. Me.Button1.Text = "讀 取" 

  43. '  

  44. 'Form1  

  45. '  

  46. Me.AutoScaleBaseSize = New 
    System.Drawing.Size(6, 14)  

  47. Me.ClientSize = New System.
    Drawing.Size(632, 517)  

  48. Me.Controls.Add(Me.Button1)  

  49. Me.Controls.Add(Me.outtext)  

  50. Me.Controls.Add(Me.input)  

  51. Me.Name = "Form1" 

  52. Me.Text = "Form1" 

  53. Me.ResumeLayout(False)  

  54. End Sub 

  1. #End Region  

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

  3. Dim doc As xmldocument = 
    New xmldocument  

  4. Dim y As String  

  5. doc.Load(input.Text)  

  6. Dim rootnode As XmlElement = 
    doc.DocumentElement  

  7. outtext.Text = "" 

  8. enumeratenode(rootnode, 0)  

  9. End Su 

  1. Private Sub enumeratenode()
    Sub enumeratenode(ByVal node 
    As XmlNode, ByVal indentval 
    As Integer)  

  2. Dim type As String  

  3. Select Case node.NodeType  

  4. Case XmlNodeType.Element  

  5. type = "元素" 

  6. Case XmlNodeType.Text  

  7. type = "文本" 

  8. Case XmlNodeType.Comment  

  9. type = "注釋" 

  10. Case Else  

  11. outtext.AppendText(".")  

  12. End Select 

  1. outtext.AppendText(type & "節(jié)點找到")  

  2. Select Case node.NodeType  

  3. Case XmlNodeType.Element  

  4. outtext.AppendText(",name=" 
    & node.Name & vbCrLf)  

  5. Case XmlNodeType.Text  

  6. outtext.AppendText(",content=" 
    & node.Value & vbCrLf)  

  7. Case XmlNodeType.Comment  

  8. outtext.AppendText(",content=" 
    & node.Value & vbCrLf)  

  9. Case Else  

  10. outtext.AppendText(".")  

  11. End Select 

  1. If Not node.Attributes Is Nothing Then  

  2. If node.Attributes.Count <> 0 Then  

  3. outtext.AppendText("此節(jié)點有屬性:")  

  4. Dim attr As XmlAttribute  

  5. For Each attr In node.Attributes  

  6. outtext.AppendText(attr.Name 
    & " =" & attr.Value & vbCrLf)  

  7. Next  

  8. End If  

  9. End If 

  1. If node.HasChildNodes Then  

  2. outtext.AppendText
    ("此節(jié)點有子節(jié)點:" & vbCrLf)  

  3. Dim child As XmlNode  

  4. For Each child In node.ChildNodes  

  5. enumeratenode(child, indentval + 1)  

  6. Next  

  7. End If  

  8. End Sub  

  9. End Class 

到此,關(guān)于“VB.NET怎么讀取XML文件”的學習就結(jié)束了,希望能夠解決大家的疑惑。理論與實踐的搭配能更好的幫助大家學習,快去試試吧!若想繼續(xù)學習更多相關(guān)知識,請繼續(xù)關(guān)注創(chuàng)新互聯(lián)網(wǎng)站,小編會繼續(xù)努力為大家?guī)砀鄬嵱玫奈恼拢?/p>

當前題目:VB.NET怎么讀取XML文件
文章出自:http://muchs.cn/article22/ihdhcc.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供ChatGPT、網(wǎng)站維護、商城網(wǎng)站、微信小程序、小程序開發(fā)、關(guān)鍵詞優(yōu)化

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

成都seo排名網(wǎng)站優(yōu)化