XmlReaderSample1.cs
上传用户:lxycoco
上传日期:2022-07-21
资源大小:38457k
文件大小:3k
源码类别:

C#编程

开发平台:

Others

  1. using System;
  2. using System.Drawing;
  3. using System.Collections;
  4. using System.ComponentModel;
  5. using System.Windows.Forms;
  6. using System.Data;
  7. using System.Xml;
  8. namespace Wrox.ProCSharp.Xml.XmlReaderSample1
  9. {
  10. /// <summary>
  11. /// Summary description for Form1.
  12. /// </summary>
  13. public class Form1 : System.Windows.Forms.Form
  14. {
  15. private System.Windows.Forms.Button button1;
  16. private System.Windows.Forms.ListBox listBox1;
  17. /// <summary>
  18. /// Required designer variable.
  19. /// </summary>
  20. private System.ComponentModel.Container components = null;
  21. public Form1()
  22. {
  23. //
  24. // Required for Windows Form Designer support
  25. //
  26. InitializeComponent();
  27. //
  28. // TODO: Add any constructor code after InitializeComponent call
  29. //
  30. }
  31. /// <summary>
  32. /// Clean up any resources being used.
  33. /// </summary>
  34. protected override void Dispose( bool disposing )
  35. {
  36. if( disposing )
  37. {
  38. if (components != null) 
  39. {
  40. components.Dispose();
  41. }
  42. }
  43. base.Dispose( disposing );
  44. }
  45. #region Windows Form Designer generated code
  46. /// <summary>
  47. /// Required method for Designer support - do not modify
  48. /// the contents of this method with the code editor.
  49. /// </summary>
  50. private void InitializeComponent()
  51. {
  52. this.button1 = new System.Windows.Forms.Button();
  53. this.listBox1 = new System.Windows.Forms.ListBox();
  54. this.SuspendLayout();
  55. // 
  56. // button1
  57. // 
  58. this.button1.Location = new System.Drawing.Point(40, 256);
  59. this.button1.Name = "button1";
  60. this.button1.Size = new System.Drawing.Size(200, 24);
  61. this.button1.TabIndex = 1;
  62. this.button1.Text = "Load XML";
  63. this.button1.Click += new System.EventHandler(this.button1_Click);
  64. // 
  65. // listBox1
  66. // 
  67. this.listBox1.Location = new System.Drawing.Point(24, 16);
  68. this.listBox1.Name = "listBox1";
  69. this.listBox1.Size = new System.Drawing.Size(232, 225);
  70. this.listBox1.TabIndex = 0;
  71. // 
  72. // Form1
  73. // 
  74. this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
  75. this.ClientSize = new System.Drawing.Size(288, 293);
  76. this.Controls.AddRange(new System.Windows.Forms.Control[] {
  77.   this.listBox1,
  78.   this.button1});
  79. this.Name = "Form1";
  80. this.Text = "Form1";
  81. this.ResumeLayout(false);
  82. }
  83. #endregion
  84. /// <summary>
  85. /// The main entry point for the application.
  86. /// </summary>
  87. [STAThread]
  88. static void Main() 
  89. {
  90. Application.Run(new Form1());
  91. }
  92.   
  93. // XmlReaderSample1/form.cs
  94. protected void button1_Click (object sender, System.EventArgs e)
  95. {
  96. // Modify this path to find books.xml
  97. // Note we only go back 1 folder
  98. string fileName = "..\..\..\books.xml";
  99. //Create the new TextReader Object
  100. XmlTextReader tr = new XmlTextReader(fileName);
  101. //Read in node at a time        
  102. while(tr.Read())  
  103. {
  104. if(tr.NodeType == XmlNodeType.Text)
  105. listBox1.Items.Add(tr.Value);
  106. }
  107. }
  108. }
  109. }