LINQ進行查詢簡單概括
本文向大家介紹LINQ進行查詢,可能好多人還不了解LINQ進行查詢,沒有關系,看完本文你肯定有不少收獲,希望本文能教會你更多東西。
LINQ to XML 提供使用 .NET 語言集成查詢 (LINQ) Framework 的內存中 XML 編程接口。LINQ to XML 使用***的 .NET Framework 語言功能,相當于更新的和重新設計的文檔對象模型 (DOM) XML 編程接口。
LINQ 系列技術提供了針對對象 (LINQ to Objects)、關系數(shù)據(jù)庫 (LINQ to SQL) 和 XML (LINQ to XML) 的一致查詢體驗。
◆有關 LINQ 和 LINQ to XML 的更多信息,請參見 項目 LINQ 網站。該網站提供有關 LINQ 項目和相關技術的白皮書。
◆有關 LINQ to XML 和其他 Microsoft XML 技術的更多信息與新聞,請參見 XML 工作組博客(可能為英文網頁)。
本文介紹直接利用LINQ進行查詢。
現(xiàn)在有一個專門的System.Xml.Linq的命名空間
- XDocument srcTree = new XDocument(
- new XComment("This is a comment"),
- new XElement("Root",
- new XElement("Child1", "data1"),
- new XElement("Child2", "data2"),
- new XElement("Child3", "data3"),
- new XElement("Child2", "data4"),
- new XElement("Info5", "info5"),
- new XElement("Info6", "info6"),
- new XElement("Info7", "info7"),
- new XElement("Info8", "info8"),
- new XElement("Test","Chenxizhang",new XAttribute("ID",10248))
- )
- )
- Console.WriteLine(srcTree);
- XDocument doc = new XDocument(
- new XComment("This is a comment"),
- new XElement("Root",
- from el in srcTree.Element("Root").Elements()
- where ((string)el).StartsWith("data")
- select el
- )
- );
- Console.WriteLine(doc);
- Console.Read();
使用命名空間的例子
- XNamespace aw = "http://www.adventure-works.com";
- XElement root = new XElement(aw + "Root",new XAttribute(XNamespace.Xmlns + "aw",
"http://www.adventure-works.com"),new XElement(aw + "Child", "child content"));- Console.WriteLine(root);
- Console.Read();
【編輯推薦】