自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

LINQ To XML定位方法

開發(fā) 后端
這里介紹LINQ To XML——定位方法,包括Ancestors:返回指定節(jié)點的所有上級元素、Descendants:返回所有指定元素名稱的后續(xù)所有相同元素集合等方面。

LINQ有很多值得學習的地方,這里我們主要介紹LINQ To XML,包括介紹LINQ To XML——定位方法等方面。

LINQ To XML定位方法

1.LINQ To XML定位方法——Ancestors:返回指定節(jié)點的所有上級元素。(AncestorsAndSelf:返回包括自己的所有上級元素)

  1. XElement Students = new XElement("Students",  
  2. new XElement("Student"  
  3. new XElement("Name", "張三"),  
  4. new XElement("Sex", "男"),  
  5. new XElement("Age",new XAttribute ("Year","1989/8/22"), 20))  
  6. );  
  7. foreach (var el in Students.Element ("Student").Element("Sex").Ancestors ())  
  8. {  
  9. Console.WriteLine(el);  

2.LINQ To XML定位方法——Descendants:返回所有指定元素名稱的后續(xù)所有相同元素集合。

  1. XElement Students = new XElement("Students",  
  2. new XElement("Student",  
  3. new XElement("Name", "張三"),  
  4. new XElement("Sex", "男"),  
  5. new XElement("Age", new XAttribute("Year", "1989/8/22"), 20)),  
  6. new XElement("Student",  
  7. new XElement("Name", "李四"),  
  8. new XElement("Sex", "女"),  
  9. new XElement("Age", new XAttribute("Year", "1990/8/22"), 20))  
  10. );  
  11. foreach (var v in Students.Descendants())  
  12. {  
  13. Console.WriteLine(v);  
  14. Console.WriteLine("-----------------------");  

3.LINQ To XML定位方法——ElementsAfterSelf:返回當前節(jié)點后的所有節(jié)點。(ElementsBeforeSelft:返回當前節(jié)點前的所有節(jié)點)

  1. XElement Students = new XElement("Students",  
  2. new XElement("Student",  
  3. new XElement("Name", "張三"),  
  4. new XElement("Sex", "男"),  
  5. new XElement("Age", new XAttribute("Year", "1989/8/22"), 20)),  
  6. new XElement("Student",  
  7. new XElement("Name", "李四"),  
  8. new XElement("Sex", "女"),  
  9. new XElement("Age", new XAttribute("Year", "1990/8/22"), 20))  
  10. );  
  11. foreach (var v in Students.Element ("Student").ElementsAfterSelf ())  
  12. {  
  13. Console.WriteLine(v);  
  14. Console.WriteLine("-----------------------");  
  15. }

【編輯推薦】

  1. LINQ查詢操作剖析
  2. LINQ生成字符串概述
  3. LINQ查詢語法簡單描述
  4. LINQ解決方案簡單概述
  5. LINQ查詢結(jié)果分析
責任編輯:佚名 來源: CSDN
相關(guān)推薦

2011-07-22 08:43:08

XML

2009-09-17 13:54:26

LINQ to XML

2009-01-04 16:58:48

LINQ to XMLLINQXML

2009-09-17 13:30:32

LINQ to XML

2009-09-14 15:12:40

LINQ to XML

2009-09-16 15:33:22

LINQ to XML

2009-09-16 16:52:50

LINQ to XML

2011-07-26 13:58:17

LINQ

2009-09-16 16:59:05

LINQ to XML

2009-09-14 16:46:15

LINQ to XML

2009-09-16 15:48:05

Linq修改XML文檔

2009-09-14 14:58:52

LINQ to XML

2009-09-14 15:45:28

LINQ刪除XML節(jié)點

2009-09-14 16:17:03

什么是LINQ To

2009-09-14 16:51:33

LINQ XML樹加載

2009-09-16 15:53:49

Linq創(chuàng)建xml文檔

2009-09-17 13:38:42

LINQ to XML

2009-09-16 16:55:07

LINQ to XML

2009-09-08 16:55:01

Linq實現(xiàn)XML轉(zhuǎn)換

2009-09-14 16:33:55

LINQ To XML
點贊
收藏

51CTO技術(shù)棧公眾號