using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
namespace 读取xml文件内容
{
class Program
{
static void Main(string[] args)
{
string path = "xzxml.xml";
//对象--加载文件
XDocument xdoc = XDocument.Load(path);
XElement xele = xdoc.Root;//获取根元素
//获取根元素下的所有子元素
IEnumerable<XElement> eles = xele.Elements();
foreach(XElement eleClass in eles)
{
foreach(XElement itemStudent in eleClass.Elements())
{
//获取Class下属性id的值
Console.WriteLine(itemStudent.Attribute("id").Value);
Console.WriteLine(itemStudent.Element("name").Value);
Console.WriteLine(itemStudent.Element("gender").Value);
Console.WriteLine(itemStudent.Element("age").Value);
Console.WriteLine("------------");
}
}
Console.ReadKey();
}
}
}