日期:2014-05-20 浏览次数:21018 次
void Main() { XDocument xml=XDocument.Load("c:\\test.xml"); var query=from x in xml.Descendants("server") select new{name=x.Element("name").Value,server_id=x.Element("server_id").Value}; foreach(var q in query) { Console.WriteLine("Name:{0}\tServerId:{1}",q.name,q.server_id); } /* Name:张三 ServerId:1 Name:李四 ServerId:2 Name:王五 ServerId:3 */ }