以下是引用片段:Form1.cs
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Xml;
namespace hellojoysou
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.DataGrid Visitors;
private System.Windows.Forms.Button GetXML;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Visitors = new System.Windows.Forms.DataGrid();
this.GetXML = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.Visitors)).BeginInit();
this.SuspendLayout();
//
// Visitors
//
this.Visitors.CaptionText = "Visitors";
this.Visitors.DataMember = "";
this.Visitors.HeaderForeColor = System.Drawing.SystemColors.ControlText;
this.Visitors.Location = new System.Drawing.Point(8, 8);
this.Visitors.Name = "Visitors";
this.Visitors.PreferredColumnWidth = 100;
this.Visitors.Size = new System.Drawing.Size(552, 184);
this.Visitors.TabIndex = 0;
this.Visitors.Navigate += new System.Windows.Forms.NavigateEventHandler(this.Visitors_Navigate);
//
// GetXML
//
this.GetXML.Location = new System.Drawing.Point(32, 240);
this.GetXML.Name = "GetXML";
this.GetXML.Size = new System.Drawing.Size(64, 16);
this.GetXML.TabIndex = 1;
this.GetXML.Text = "GetXML";
this.GetXML.Click += new System.EventHandler(this.GetXML_Click);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(568, 278);
this.Controls.Add(this.GetXML);
this.Controls.Add(this.Visitors);
this.MaximizeBox = false;
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
((System.ComponentModel.ISupportInitialize)(this.Visitors)).EndInit();
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void Form1_Load(object sender, System.EventArgs e)
{
}
private void GetXML_Click(object sender, System.EventArgs e)
{
XmlDocument xml=new XmlDocument(); //关键用默认构造函数创建XmlDocument
xml.Load("http://www.joysou.com/system/nothing.asp"); //加载XML文件
XmlNode root=xml.DocumentElement.SelectNodes("/JoySou").Item(0);
XmlNodeList visitor=root.SelectNodes("Info/Visitors/Visitor");
DataTable dt = new DataTable();
dt.Columns.Add(new DataColumn("Name", typeof(string)));
dt.Columns.Add(new DataColumn("Ip", typeof(string)));
dt.Columns.Add(new DataColumn("address", typeof(string)));
dt.Columns.Add(new DataColumn("os", typeof(string)));
dt.Columns.Add(new DataColumn("soft", typeof(string)));
for (int i=0;i<visitor.Count;i++)
{
XmlAttributeCollection Tnode=visitor.Item(i).Attributes;
dt.Rows.Add(new string[] {Tnode["name"].Value,Tnod