成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

VB.NET讀取XML文件實現技巧分享

開發 后端
VB.NET讀取XML文件是開發人員經常會使用到的一個編程操作。初學者們在學習的過程中需要對這樣的基礎方法進行詳細的解讀,才能方便以后的應用。

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

 

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

  1. Imports System.xml  
  2. Public Class Form1Class Form1  
  3. Inherits System.Windows.Forms.Form  
  4. #Region " Windows 窗體設計器生成的代碼 "  
  5. Public Sub New()Sub New()  
  6. MyBase.New()  
  7. '該調用是 Windows 窗體設計器所必需的。  
  8. InitializeComponent()  
  9. '在 InitializeComponent() 
    調用之后添加任何初始化  
  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 窗體設計器所必需的  
  2. Private components As System.
    ComponentModel.IContainer  
  3. '注意: 以下過程是 Windows 窗體設計
    器所必需的  
  4. '可以使用 Windows 窗體設計器修改此過程。  
  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 & "節點找到")  
  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("此節點有屬性:")  
  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
    ("此節點有子節點:" & 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 

VB.NET讀取XML文件實現代碼的編寫方法如上所示。

責任編輯:曹凱 來源: 博客園
相關推薦

2010-01-18 16:33:57

VB.NET加密文件

2010-01-18 18:50:26

VB.NET鼠標手勢

2010-01-15 19:04:09

2010-01-14 16:04:32

VB.NET顯示時間

2010-01-18 16:41:47

VB.NET用戶登錄頁

2010-01-18 10:26:19

VB.NET中心旋轉圖

2010-01-13 10:25:30

VB.NET文件夾操作

2010-01-22 11:02:30

VB.NET創建新變量

2010-01-13 15:52:59

VB.NET浮動窗體

2010-01-22 13:16:05

VB.NET初始化數組

2010-01-13 16:45:44

VB.NET刪除控件

2010-01-11 15:31:04

VB.NET拖動窗體

2011-03-30 15:16:27

VB.NET.NETXML

2010-01-08 18:31:45

VB.NET歷史菜單

2009-11-03 13:16:58

VB.NET讀取文件

2010-01-12 17:02:54

VB.NET文件上傳

2010-01-15 19:24:42

2010-01-22 16:27:19

VB.NET關于對話框

2010-01-19 15:30:44

VB.NET比較運算符

2010-01-11 16:04:10

VB.NET使用wit
點贊
收藏

51CTO技術棧公眾號

主站蜘蛛池模板: 日韩精品区| 人人插人人 | 亚洲精色| 国产伦精品 | 国产一在线观看 | 日韩综合色| 欧美日韩1区2区3区 欧美久久一区 | 日本成人中文字幕 | 日韩精品激情 | 欧美日韩一区在线观看 | 欧美一级免费看 | 成人在线免费电影 | 午夜激情免费 | avav在线看 | 日韩三级在线观看 | 欧美精品欧美精品系列 | 精品视频一区二区 | 一区二区三区精品视频 | 亚洲精品免费观看 | 亚洲精品久久久久久久久久久久久 | 欧美一级三级 | 一区二区三区免费在线观看 | 99精品久久| 黄色a视频 | 亚洲在线电影 | 男人天堂久久 | 亚洲欧美视频 | 欧美婷婷| 日韩欧美亚洲 | 韩日一区| 精品综合久久久 | 精品一区二区三 | 国产精品免费在线 | 欧美日韩视频在线第一区 | 久热久热 | 日日噜噜噜夜夜爽爽狠狠视频, | 国产伦精品一区二区三区高清 | 欧美一区不卡 | 精品亚洲永久免费精品 | 国产亚洲精品综合一区 | 国产精品亚洲欧美日韩一区在线 |