Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
245 views
in Technique[技术] by (71.8m points)

c# - HtmlAgilityPack using Linq for windows phone 8.1 platform

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;

I searched over stackoverflow and google and got an Idea that It's still possible to select nodes using Linq.

I'm seeking for a block of code which will work like SelectNodes, SelectNode.

Loading the HtmlDocument asynchronously would be appreciated.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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;

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).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...