使用Linq for Windows Phone 8.1平台的HtmlAgilityPack [英] HtmlAgilityPack using Linq for windows phone 8.1 platform
问题描述
由于Windows Phone 8.1尚不支持HtmlAgilityPack,因此在项目中手动引用是一个绝妙的解决方案.但这不是唯一的问题.我可以在过去的项目中使用XPath
来选择节点.现在我可以看到HtmlDocumentNode.SelectNode()
函数不再存在(因为可能存在版本兼容性).
As HtmlAgilityPack is yet not supported in windows phone 8.1,referencing manually in the project was a trick solution. But this is not the only problem. I could use XPath
for my past project to select nodes. Now I can see that HtmlDocumentNode.SelectNode()
function is no more(because of version compatibility may be).
我在过去的项目中使用的类似于此
what I used in my past project was similar to this
HtmlNode parent = document.DocumentNode.SelectSingleNode("//ul[@class='songs-list1']");
HtmlNodeCollection x = parent.ChildNodes;
我搜索了stackoverflow和google,并得到了一个想法,即仍然可以使用Linq选择节点.
I searched over stackoverflow and google and got an Idea that It's still possible to select nodes using Linq.
我正在寻找将与SelectNodes
,SelectNode
类似的代码块.
I'm seeking for a block of code which will work like SelectNodes
, SelectNode
.
不胜感激地加载HtmlDocument
.
推荐答案
如果您打算将使用XPath的当前代码转换为使用LINQ,则可以这样做:
If you meant to translate your current code which using XPath to be using LINQ, then this will do :
HtmlNode parent = document.DocumentNode
.Descendants("ul")
.FirstOrDefault(o => o.GetAttributeValue("class", "")
== "songs-list1")
HtmlNodeCollection x = parent.ChildNodes;
但是,如果您希望找到在Windows Phone 8.1通用应用程序或Windows RT的HtmlAgilityPack版本中接受XPath的方法("我正在寻找可以像SelectNodes
,SelectNode
一样工作的代码块"),最好不要: HtmlAgilityPack& Windows 8 Metro Apps (由HAP的作者回答).
But if you expect to find methods that accept XPath in HtmlAgilityPack version for Windows Phone 8.1 universal apps or Windows RT ("I'm seeking for a block of code which will work like SelectNodes
, SelectNode
"), you better don't : HtmlAgilityPack & Windows 8 Metro Apps (answer by the author of HAP).
这篇关于使用Linq for Windows Phone 8.1平台的HtmlAgilityPack的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!