I'm glad to give you an answer!
Xml is actually a simple local database
I just made a simple one .. But the truth is the same.
// Xml file information
<Abc>
<Field> 100 </Field>
<Item>
<Id> 1 </id>
<Name> zhangsan </name>
<Sex> male </sex>
</Item>
<Item>
<Id> 2 </id>
<Name> lisi </name>
<Sex> male </sex>
</Item>
</Abc>
// Entity class.
Public class Information
{
Private string id;
Public string Id
{
Get {return id ;}
Set {id = value ;}
}
Private string name;
Public string Name
{
Get {return name ;}
Set {name = value ;}
}
Private string sex;
Public string Sex
{
Get {return sex ;}
Set {sex = value ;}
}
Public Information ()
{
}
Public Information (string id, string name, string sex)
{
This. Id = id;
This. Name = name;
This. Sex = sex;
}
}
// Read the file information in xml
List <Information> list = new List <Information> ();
// Instantiate xml
XmlDocument xml = new XmlDocument ();
// Read the xml file
Xml. Load (@ "E: \ C # \ S2C # \ DLCL \ Print computer \ MyComputer \ XulieHua \ XML. xml"); // your xml address
String id = "";
String name = "";
String sex = "";
Information info = null;
//// // ******* Start to read xml file information cyclically ********/
///////////////
Foreach (XmlNode node in xml. ChildNodes)
{
If (node. Name = "abc ")
{
Foreach (XmlNode node1 in node. ChildNodes)
{
If (node1.Name = "item ")
{
Foreach (XmlNode node2 in node1.ChildNodes)
{
Switch (node2.Name)
{
Case "id ":
Id = node2.InnerText;
Break;
Case "name ":
Name = node2.InnerText;
Break;
Default:
Sex = node2.InnerText;
Break;
}
}
Info = new Information (id, name, sex );
// Save the information to the set
List. Add (info );
}
}
}
}
All the information in xml is in the list set .. Simple .. Hey ..
Of course, you can do multiple tables and multiple field attributes ..