LINQ进行查询简单概括

本文向大家介绍LINQ进行查询,可能好多人还不了解LINQ进行查询,没有关系,看完本文你肯定有不少收获,希望本文能教会你更多东西。

LINQ to XML 提供使用 .NET 语言集成查询 (LINQ) Framework 的内存中 XML 编程接口。LINQ to XML 使用***的 .NET Framework 语言功能,相当于更新的和重新设计的文档对象模型 (DOM) XML 编程接口。

LINQ 系列技术提供了针对对象 (LINQ to Objects)、关系数据库 (LINQ to SQL) 和 XML (LINQ to XML) 的一致查询体验。
◆有关 LINQ 和 LINQ to XML 的更多信息,请参见 项目 LINQ 网站。该网站提供有关 LINQ 项目和相关技术的白皮书。
◆有关 LINQ to XML 和其他 Microsoft XML 技术的更多信息与新闻,请参见 XML 工作组博客(可能为英文网页)。

本文介绍直接利用LINQ进行查询。

现在有一个专门的System.Xml.Linq的命名空间

 
 
 
  1. XDocument srcTree = new XDocument(  
  2. new XComment("This is a comment"),  
  3. new XElement("Root",  
  4. new XElement("Child1", "data1"),  
  5. new XElement("Child2", "data2"),  
  6. new XElement("Child3", "data3"),  
  7. new XElement("Child2", "data4"),  
  8. new XElement("Info5", "info5"),  
  9. new XElement("Info6", "info6"),  
  10. new XElement("Info7", "info7"),  
  11. new XElement("Info8", "info8"),  
  12. new XElement("Test","Chenxizhang",new XAttribute("ID",10248))  
  13. )  
  14. )  
  15. Console.WriteLine(srcTree);  
  16. XDocument doc = new XDocument(  
  17. new XComment("This is a comment"),  
  18. new XElement("Root",  
  19. from el in srcTree.Element("Root").Elements()  
  20. where ((string)el).StartsWith("data")  
  21. select el  
  22. )  
  23. );  
  24. Console.WriteLine(doc);  
  25. Console.Read(); 

使用命名空间的例子

 
 
 
  1. XNamespace aw = "http://www.adventure-works.com";  
  2. XElement root = new XElement(aw + "Root",new XAttribute(XNamespace.Xmlns + "aw", 
    "http://www.adventure-works.com"),new XElement(aw + "Child", "child content"));  
  3. Console.WriteLine(root);  
  4. Console.Read(); 

【编辑推荐】

  1. LINQ to SQL查询分析
  2. LINQ查询架构简单介绍
  3. LINQ to SQL映射关系概述
  4. LINQ To SQL对象模型浅析
  5. LINQ to SQL映射列描述
THE END