//khởi tạo đối tượng XmlDoc
System.Xml.XmlDocument xmlDoc
= new System.Xml.XmlDocument(); {
//load dử liều
xmlDoc.Load("data.xml");
//load các trạng thái cho ứng dụng
this.Top = int.Parse(xmlDoc
.DocumentElement["top"].InnerText); this.Left = int.Parse(xmlDoc
.DocumentElement["left"].InnerText); this.Width = int.Parse(xmlDoc
.DocumentElement["width"].InnerText); this.Height = int.Parse(xmlDoc
.DocumentElement["height"].InnerText);
for(int i
=0; i
<xmlDoc
.DocumentElement["items"].ChildNodes.Count;i
++) {
listBox1.Items.Add(xmlDoc.DocumentElement["items"].ChildNodes[i].InnerText);
}
}
{
System.IO.StreamWriter sw
= new System.IO.StreamWriter("data.xml"); sw.WriteLine("<?xml version='1.0' encoding='utf-8'?>");
sw.WriteLine("<data>");
sw.WriteLine(" <width>460</width>");
sw.WriteLine(" <height>379</height>");
sw.WriteLine(" <top>100</top>");
sw.WriteLine(" <left>100</left>");
sw.WriteLine(" <items>");
sw.WriteLine(" <item>a</item>");
sw.WriteLine(" <item>b</item>");
sw.WriteLine(" <item>c</item>");
sw.WriteLine(" </items>");
sw.WriteLine("</data>");
sw.Close();
//load dử liều
xmlDoc.Load("data.xml");
//load các trạng thái cho ứng dụng
this.Top = int.Parse(xmlDoc
.DocumentElement["top"].InnerText); this.Left = int.Parse(xmlDoc
.DocumentElement["left"].InnerText); this.Width = int.Parse(xmlDoc
.DocumentElement["width"].InnerText); this.Height = int.Parse(xmlDoc
.DocumentElement["height"].InnerText);
for(int i
=0; i
<xmlDoc
.DocumentElement["items"].ChildNodes.Count;i
++) {
listBox1.Items.Add(xmlDoc.DocumentElement["items"].ChildNodes[i].InnerText);
}
}