Form1.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 MSXML2;
  8. namespace Wrox.ProCSharp.Xml.MSXMLTest
  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. private DOMDocument30Class doc;
  22. public Form1()
  23. {
  24. //
  25. // Required for Windows Form Designer support
  26. //
  27. InitializeComponent();
  28. //
  29. // TODO: Add any constructor code after InitializeComponent call
  30. //
  31. }
  32. /// <summary>
  33. /// Clean up any resources being used.
  34. /// </summary>
  35. protected override void Dispose( bool disposing )
  36. {
  37. if( disposing )
  38. {
  39. if (components != null) 
  40. {
  41. components.Dispose();
  42. }
  43. }
  44. base.Dispose( disposing );
  45. }
  46. #region Windows Form Designer generated code
  47. /// <summary>
  48. /// Required method for Designer support - do not modify
  49. /// the contents of this method with the code editor.
  50. /// </summary>
  51. private void InitializeComponent()
  52. {
  53. this.button1 = new System.Windows.Forms.Button();
  54. this.listBox1 = new System.Windows.Forms.ListBox();
  55. this.SuspendLayout();
  56. // 
  57. // button1
  58. // 
  59. this.button1.Location = new System.Drawing.Point(40, 256);
  60. this.button1.Name = "button1";
  61. this.button1.Size = new System.Drawing.Size(200, 24);
  62. this.button1.TabIndex = 1;
  63. this.button1.Text = "Load XML";
  64. this.button1.Click += new System.EventHandler(this.button1_Click_1);
  65. // 
  66. // listBox1
  67. // 
  68. this.listBox1.Location = new System.Drawing.Point(24, 16);
  69. this.listBox1.Name = "listBox1";
  70. this.listBox1.Size = new System.Drawing.Size(232, 225);
  71. this.listBox1.TabIndex = 0;
  72. this.listBox1.SelectedIndexChanged += new System.EventHandler(this.listBox1_SelectedIndexChanged_1);
  73. // 
  74. // Form1
  75. // 
  76. this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
  77. this.ClientSize = new System.Drawing.Size(288, 293);
  78. this.Controls.AddRange(new System.Windows.Forms.Control[] {
  79.   this.listBox1,
  80.   this.button1});
  81. this.Name = "Form1";
  82. this.Text = "Form1";
  83. this.ResumeLayout(false);
  84. }
  85. #endregion
  86. /// <summary>
  87. /// The main entry point for the application.
  88. /// </summary>
  89. [STAThread]
  90. static void Main() 
  91. {
  92. Application.Run(new Form1());
  93. }
  94.   
  95. private void button1_Click_1(object sender, System.EventArgs e)
  96. {
  97. doc=new DOMDocument30Class();
  98. doc.load("..\..\..\books.xml");
  99. IXMLDOMNodeList nodes;
  100. nodes = doc.selectNodes("bookstore/book");
  101. IXMLDOMNode node=nodes.nextNode();
  102. while(node!=null)  
  103. {
  104. listBox1.Items.Add(node.attributes.getNamedItem("ISBN").text);
  105. node=nodes.nextNode ();
  106. }
  107. }
  108. private void listBox1_SelectedIndexChanged_1(object sender, System.EventArgs e)
  109. {
  110. string srch=listBox1.SelectedItem.ToString();
  111. IXMLDOMNode nd=doc.selectSingleNode(
  112. "bookstore/book[@ISBN='" + srch + "']");
  113. MessageBox.Show(nd.text);
  114. }
  115. }
  116. }