xml| traversal
Using System;
Using System.Drawing;
Using System.Collections;
Using System.ComponentModel;
Using System.Windows.Forms;
Using System.Data;
Using System.IO;
Using System.Xml;
Namespace WindowsApplication2
{
<summary>
Summary description of the Form1.
</summary>
public class Form1:System.Windows.Forms.Form
{
Private System.Windows.Forms.Button button1;
<summary>
The required designer variable.
</summary>
Private System.ComponentModel.Container components = null;
Const string mypath=@ "D:\nba2004";
XmlDocument doc=new XmlDocument ();
Public Form1 ()
{
//
Required for Windows Forms Designer support
//
InitializeComponent ();
//
TODO: Add any constructor code after the InitializeComponent call
//
}
<summary>
Clean up all resources that are in use.
</summary>
protected override void Dispose (bool disposing)
{
if (disposing)
{
if (Components!= null)
{
Components. Dispose ();
}
}
Base. Dispose (disposing);
}
Code generated #region the Windows forms Designer
<summary>
Designer supports required methods-do not use the Code editor to modify
The contents of this method.
</summary>
private void InitializeComponent ()
{
This.button1 = new System.Windows.Forms.Button ();
This. SuspendLayout ();
//
Button1
//
This.button1.Location = new System.Drawing.Point (192, 232);
This.button1.Name = "Button1";
This.button1.Size = new System.Drawing.Size (88, 24);
This.button1.TabIndex = 0;
This.button1.Text = "Button1";
This.button1.Click + = new System.EventHandler (THIS.BUTTON1_CLICK1);
//
Form1
//
This. AutoScaleBaseSize = new System.Drawing.Size (6, 14);
This. ClientSize = new System.Drawing.Size (292, 273);
This. Controls.Add (This.button1);
This. Name = "Form1";
This. Text = "Form1";
This. ResumeLayout (FALSE);
}
#endregion
<summary>
The main entry point for the application.
</summary>
[STAThread]
static void Main ()
{
Application.Run (New Form1 ());
}
private void Button1_click1 (object sender, System.EventArgs e)
{
String Mypath=mypath. ToUpper ();
Doc. Loadxml ("<fileinfo name= '" +mypath+ "' ></FileInfo>");
GetFileInfo (Mypath,doc. DocumentElement);
Doc. Save (@ "D:\fileinfo.xml");
}
private void GetFileInfo (string strpath,system.xml.xmlnode node)
{
DirectoryInfo dirinfo=new DirectoryInfo (strpath);
foreach (DirectoryInfo dirinfo in Dirinfo.getdirectories ())
{
XmlElement elem = doc. CreateElement ("dir");
Elem. SetAttribute ("Name", Dirinfo.) Name);
Elem. SetAttribute ("LastWriteTime", Dirinfo. Lastwritetime.tostring ());
Node. AppendChild (Elem);
GetFileInfo (Dirinfo. Fullname,elem);
}
foreach (FileInfo FileInfo in Dirinfo.getfiles ())
{
XmlElement elem = doc. createelement ("file");
Elem. SetAttribute ("Name", FileInfo.) Name);
Elem. SetAttribute ("LastWriteTime", FileInfo. Lastwritetime.tostring ());
Elem. SetAttribute ("Length", FileInfo. Length.tostring ());
Node. AppendChild (Elem);
}
}
}
}