C#第2个程序,读取偶网站的数据!

王朝c#·作者佚名  2006-01-09
宽屏版  字体: |||超大  

由于偶网站是用XML搞D...说白了就是读XML而已(不要揍偶...)程序再最最下面,而且如果你觉得不一定是偶网站当前数据的话,欢迎http://www.joysou.com 嘿嘿,正想拉点人呢..

以下是引用片段: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,Tnode["ip"].Value,Tnode["address"].Value,Tnode["os"].Value,Tnode["soft"].Value});

}

Visitors.DataSource = dt;

}

private void Visitors_Navigate(object sender, System.Windows.Forms.NavigateEventArgs ne)

{

}

}

}

hellojoysou.exe

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
© 2005- 王朝网络 版权所有