Linq To XML:在结点下查询某一类型结点
2011-04-21 16:15
387 查看
下面的方法是查询 element 元素类型的结点
输出
firstParticipant.Nodes().OfType<XElement>()
想取什么类型就在OfType里写吧,真的好简单
XElement firstParticipant; // A full document with all the bells and whistles. XDocument xDocument = new XDocument( new XDeclaration("1.0", "UTF-8", "yes"), new XDocumentType("BookParticipants", null, "BookParticipants.dtd", null), new XProcessingInstruction("BookCataloger", "out-of-print"), // Notice on the next line that we are saving off a reference to the first // BookParticipant element. new XElement("BookParticipants", firstParticipant = new XElement("BookParticipant", new XComment("This is a new author."), new XProcessingInstruction("AuthorHandler", "new"), new XAttribute("type", "Author"), new XElement("FirstName", "Joe"), new XElement("LastName", "Rattz")), new XElement("BookParticipant", new XAttribute("type", "Editor"), new XElement("FirstName", "Ewan"), new XElement("LastName", "Buckingham")))); foreach (XNode node in firstParticipant.Nodes().OfType<XElement>()) { Console.WriteLine(node); }
输出
<FirstName>Joe</FirstName> <LastName>Rattz</LastName>
firstParticipant.Nodes().OfType<XElement>()
想取什么类型就在OfType里写吧,真的好简单
相关文章推荐
- LINQ之路18:LINQ to XML之导航和查询
- linq to xml查询绑定GridView
- linq to xml 初学 -- 查询语法
- LINQ to ADO.net 中如何查询弱类型的Datatable
- 用Linq to XML的方式查询XML 文档
- 在 LINQ to Entities 查询中无法构造实体或复杂类型
- LINQ To XML:之复杂的查询举例
- LINQ之路18:LINQ to XML之导航和查询
- 步步为营VS 2008 + .NET 3.5(14) - XLINQ(LINQ to XML)之针对XML文件的添加、查询、更新和删除
- [代码]使用LINQ的查询结果填充XML树(LINQ to XML)
- Linq to XML说法——(一)创建,添加,查询
- 一、Linq to XML (创建,添加,查询)
- LinQ To XML——用LinQ查询XML
- 在 LINQ to Entities 查询中无法构造实体或复杂类型
- Linq To Xml实现类似XPath查询(Silverlight下的XPath)
- Linq to SQL中报错"不允许在查询中显式构造实体类型"怎么解决
- (转)一、Linq to XML (创建,添加,查询)
- hibernate mapping文件中 xmlns会导致linq to xml 查询不到对应的节点
- Linq to SQL中报错"不允许在查询中显式构造实体类型"怎么解决
- C#程序中使用LINQ to XML来查询XML格式数据的实例