
- //获取root节点
- XElement root = XElement.Load(Server.MapPath("~/路径文件名"));
- //根据路径得到值root里面的第一个子节点;
- XElement book = root.Element("Books");//将root节点下的所有同一级节点Tolist
- List<System.Xml.Linq.XElement> BookName = book.Elements().ToList();
- //根据索引获取root里面的第一个节点
-
-
- //获取第一个节点里面的节点
- XElement booktitle = BookName[0];
-
- //获取id属性
- string Id = booktitle.Attribute("Id").Value;
-
- //获取名称
- string name = booktitle.Name;
-
- //获取该节点里面的名称
- string FirstBookname = booktitle.Element("该节点里面节点的名称").Value;
评价