排名
7
文章
192
粉丝
15
评论
16
ICP备案 :渝ICP备18016597号-1
网站信息:2018-2025TNBLOG.NET
技术交流:群号656732739
联系我们:contact@tnblog.net
公网安备:
50010702506256


欢迎加群交流技术

首先通过路径找到XML文件
- //通过指定路径找到XML文件
- XElement xDoc = XElement.Load(Server.MapPath("~/xml/labery.xml"));
找到根节点下的节点信息
- //books有多个用集合
- List<XElement> x = xDoc.Elements("books").ToList();
-
- //books有一个用对象
- XElement x = xDoc.Element("books").Value;
创建相同名字的节点
- //子节点
- XElement books = new XElement("books");
- labery.Add(books);
- //子节点下边的子节点
- string b1 = "斗破苍穹";
- books.Add(new XElement("bookname", b1));
- books.Add(new XElement("bookmoney", "36$"));
- books.Add(new XElement("bookkind", "武侠"));
- books.Add(new XElement("bookpaper", "区区斗皇............."));
-
-
- books = new XElement("books");
- string b2 = "斗罗大陆";
- books.Add(new XElement("bookname", b2));
- books.Add(new XElement("bookmoney", "33$"));
- books.Add(new XElement("bookkind", "仙侠"));
- books.Add(new XElement("bookpaper", "区区八个魂环............."));
- labery.Add(books);
-
-
-
-
- books = new XElement("books");
- string b3 = "王者荣耀";
- books.Add(new XElement("bookname", b3));
- books.Add(new XElement("bookmoney", "12$"));
- books.Add(new XElement("bookkind", "游戏"));
- books.Add(new XElement("bookpaper", "区区最强王者............."));
- labery.Add(books);
评价