1开始:
<?xml version="1.0" encoding="utf-8" ?> <students> <studnet id="12313"> <name>赵</name> <age>18</age> </studnet> <student id="snajdsabja"> <name>钱</name> <age>20</age> </student> </students>
2编写:
用双重循环编译出xml文件:
XmlDocument myxml = new XmlDocument();
myxml.Load("XMLF.xml");
XmlNode XML = myxml.DocumentElement;
//foreach (XmlNode it in XML.ChildNodes)
//{
// foreach(XmlNode item in it.ChildNodes.){
// switch(item.Name){
// case "name":
// Console.WriteLine("名字是:{0}",item.InnerText);
// break;
// case "age":
// Console.WriteLine("年龄是:{0}", item.InnerText);
// break;
// }
// }
//}
用一个循环写出
//用一个循环
//foreach(XmlNode it in XML.ChildNodes){
// Console.Write(it["name"].InnerText);
// Console.Write(it["age"].InnerText);
// Console.WriteLine();
//}
查询出标签的属性()(重点):
foreach(XmlNode item in XML.ChildNodes){
string str = item.Attributes["id"].Value;
Console.WriteLine("id为:"+str);
}