LINQ進(jìn)行查詢簡(jiǎn)單概括
本文向大家介紹LINQ進(jìn)行查詢,可能好多人還不了解LINQ進(jìn)行查詢,沒有關(guān)系,看完本文你肯定有不少收獲,希望本文能教會(huì)你更多東西。
LINQ to XML 提供使用 .NET 語言集成查詢 (LINQ) Framework 的內(nèi)存中 XML 編程接口。LINQ to XML 使用***的 .NET Framework 語言功能,相當(dāng)于更新的和重新設(shè)計(jì)的文檔對(duì)象模型 (DOM) XML 編程接口。
LINQ 系列技術(shù)提供了針對(duì)對(duì)象 (LINQ to Objects)、關(guān)系數(shù)據(jù)庫(kù) (LINQ to SQL) 和 XML (LINQ to XML) 的一致查詢體驗(yàn)。
◆有關(guān) LINQ 和 LINQ to XML 的更多信息,請(qǐng)參見 項(xiàng)目 LINQ 網(wǎng)站。該網(wǎng)站提供有關(guān) LINQ 項(xiàng)目和相關(guān)技術(shù)的白皮書。
◆有關(guān) LINQ to XML 和其他 Microsoft XML 技術(shù)的更多信息與新聞,請(qǐng)參見 XML 工作組博客(可能為英文網(wǎng)頁(yè))。
本文介紹直接利用LINQ進(jìn)行查詢。
現(xiàn)在有一個(gè)專門的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();
【編輯推薦】