Linq转Xml [英] Linq To Xml

查看:58
本文介绍了Linq转Xml的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

显示我对Linq to Xml的理解不清,并寻求帮助.我正在尝试执行此强制转换,然后执行查询.

displaying my weak understanding of Linq to Xml and asking for help. I was trying to do this cast and then do a query.

<身体>
XmlDocument doc == XmlDocument(();
doc.Load(path);
,XmlNodeList rootNodeList = doc .GetElementsByTagName("root");
XmlNode rootNode = rootNodeList .Item(0);
的System.Collections.IEnumerable que ==(System.Collections.IEnumerable)rootNode.ChildNodes .Cast < XmlNode > ; ();
XmlNode元素;
qMethods que
elem.Name == this.ext + Globals.hostName
请选择(elem).Take(1);
XmlDocument doc = new XmlDocument ( );  
                doc.Load ( path );  
                XmlNodeList rootNodeList = doc.GetElementsByTagName ( "root" );  
                XmlNode rootNode = rootNodeList.Item ( 0 );  
                System.Collections.IEnumerable que = ( System.Collections.IEnumerable )rootNode.ChildNodes.Cast<XmlNode> ( );  
                   
                XmlNode elem;  
                var qMethods = ( from elem in que  
                                 where elem.Name == this.ext + "Files_" + Globals.hostName  
                                 select elem ).Take ( 1 ); 

推荐答案

我认为您将需要使用具体的实现,因此LINQ引擎可以使用正确的查询.传入XNode;不要将其转换为IEnumerable.

I think you're going to need to use the concrete implementations so the LINQ engine can use the correct queries. Pass in the XNode; don't cast it to IEnumerable.


这篇关于Linq转Xml的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆